Skip to content

Commit

Permalink
更新 com.feilong.security.oneway.SHA384Util javadoc fix #693
Browse files Browse the repository at this point in the history
新建 com.feilong.security.oneway.SHA384Util.encodeUpperCase(String) 返回大写结果
fix #694
  • Loading branch information
venusdrogon committed Jan 26, 2024
1 parent 213d424 commit 6a89785
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,18 @@
import com.feilong.security.EncryptionException;

/**
* The Class SHA384Util.
*
* SHA384是一种安全散列算法,也称为SHA-384.
*
* <p>
* SHA384是由美国国家标准与技术研究所(NIST)设计并于2006年发表的密码散列算法,属于SHA-3系列。
*
* 需要注意的是,不同的机构和组织可能会使用不同的名称来描述这种算法,如NESSIE、NISTsha等。但实际上,它们都是同一种算法的不同称呼。
*
* SHA384与SHA256类似,但产生的信息摘要长度为384位,而不是256位。它也是分组算法,分组长度为1024位。
*
* SHA384属于密码杂凑算法,原则上不能通过密文推出明文。它被设计得非常安全,难以发生碰撞,因此被广泛应用于各种加密和安全应用中,如数字签名、身份验证和数据完整性检查等。
* </p>
*
* @author <a href="https://github.com/ifeilong/feilong">feilong</a>
* @see OnewayType#SHA384
* @since 1.14.2
Expand All @@ -42,15 +52,26 @@ private SHA384Util(){
//---------------------------------------------------------------

/**
* 使用sha384算法 单向加密字符串.
* 使用sha384算法 单向加密字符串(小写).
*
* <p>
* 加密之后的转成<span style="color:green">小写的</span>16进制字符串
* </p>
*
* <h3>示例:</h3>
* <blockquote>
*
* <pre class="code">
* SHA384Util.encode("") = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b"
* SHA384Util.encode("123456") = "0a989ebc4a77b56a6e2bb7b19d995d185ce44090c13e2984b7ecc6d446d4b61ea9991b76a4c2f04b1b4d244841449454"
* </pre>
*
* </blockquote>
*
* @param origin
* 原始字符串,将使用默认的 {@link String#getBytes()} 转成字节数组<br>
* @return 加密之后的转成小写的16进制字符串
* @return 加密之后的转成小写的16进制字符串<br>
* 如果 <code>origin</code> 是null,抛出 {@link NullPointerException}<br>
* @throws EncryptionException
* 如果在加密解密的过程中发生了异常,会以EncryptionException形式抛出
* @see OnewayEncryption#encode(OnewayType, String)
Expand All @@ -60,6 +81,37 @@ public static String encode(String origin){
return OnewayEncryption.encode(ONEWAYTYPE, origin);
}

/**
* 使用sha384算法 单向加密字符串(大写).
*
* <p>
* 加密之后的转成<span style="color:green">大写的</span>16进制字符串
* </p>
*
* <h3>示例:</h3>
* <blockquote>
*
* <pre class="code">
* SHA384Util.encodeUpperCase("") = "38B060A751AC96384CD9327EB1B1E36A21FDB71114BE07434C0CC7BF63F6E1DA274EDEBFE76F65FBD51AD2F14898B95B"
* SHA384Util.encodeUpperCase("123456") = "0A989EBC4A77B56A6E2BB7B19D995D185CE44090C13E2984B7ECC6D446D4B61EA9991B76A4C2F04B1B4D244841449454"
* </pre>
*
* </blockquote>
*
* @param origin
* 原始字符串,将使用默认的 {@link String#getBytes()} 转成字节数组<br>
* @return 加密之后的转成大写的16进制字符串<br>
* 如果 <code>origin</code> 是null,抛出 {@link NullPointerException}<br>
* @throws EncryptionException
* 如果在加密解密的过程中发生了异常,会以EncryptionException形式抛出
* @see OnewayEncryption#encode(OnewayType, String)
* @see com.feilong.lib.codec.digest.DigestUtils#sha384Hex(String)
* @since 4.0.8
*/
public static String encodeUpperCase(String origin){
return OnewayEncryption.encodeUpperCase(ONEWAYTYPE, origin);
}

/**
* 使用sha384算法 单向加密字符串.
*
Expand All @@ -72,7 +124,8 @@ public static String encode(String origin){
* 如果需要string 转码,请自行调用value.getBytes(string chartsetname),再调用{@link #encode(String, String)}
* @param charsetName
* 受支持的 {@link CharsetType} 名称,比如 utf-8
* @return 加密之后的转成小写的16进制字符串
* @return 加密之后的转成小写的16进制字符串<br>
* 如果 <code>origin</code> 是null,抛出 {@link NullPointerException}<br>
* @throws EncryptionException
* 如果在加密解密的过程中发生了异常,会以EncryptionException形式抛出
* @see OnewayEncryption#encode(OnewayType, String, String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.junit.runners.Suite.SuiteClasses;

import com.feilong.security.oneway.OnewayEncryptionParameterizedTest;
import com.feilong.security.oneway.SHA384UtilTest;
import com.feilong.security.oneway.SHA512UtilTest;
import com.feilong.security.oneway.md5.Md5EncodeFileTest;
import com.feilong.security.oneway.md5.Md5EncodeParameterizedTest;
Expand All @@ -31,6 +30,8 @@
import com.feilong.security.oneway.sha1.Sha1EncodeFileTest;
import com.feilong.security.oneway.sha256.SHA256UtilTest;
import com.feilong.security.oneway.sha256.Sha256EncodeFileTest;
import com.feilong.security.oneway.sha384.SHA384UtilTest;
import com.feilong.security.oneway.sha384.Sha384EncodeFileTest;
import com.feilong.security.symmetric.AesUtilTest;

@RunWith(Suite.class)
Expand All @@ -50,6 +51,8 @@
Sha256EncodeFileTest.class,

SHA384UtilTest.class,
Sha384EncodeFileTest.class,

SHA512UtilTest.class,

OnewayEncryptionParameterizedTest.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (C) 2008 feilong
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.feilong.security.oneway.sha384;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import com.feilong.lib.codec.digest.DigestUtils;
import com.feilong.security.AbstractSecurityTest;
import com.feilong.security.oneway.SHA384Util;

public class SHA384UtilTest extends AbstractSecurityTest{

@Test
public void encode121(){
assertEquals(DigestUtils.sha384Hex("2284208963"), SHA384Util.encode("2284208963"));
}

@Test
public void encode12(){
LOGGER.debug(debugSecurityValue(SHA384Util.encode("2284208963")));
}

//---------------------------------------------------------------

@Test
public void encodeUpperCase(){
assertEquals(
"0A989EBC4A77B56A6E2BB7B19D995D185CE44090C13E2984B7ECC6D446D4B61EA9991B76A4C2F04B1B4D244841449454",
SHA384Util.encodeUpperCase("123456"));
assertEquals(
"38B060A751AC96384CD9327EB1B1E36A21FDB71114BE07434C0CC7BF63F6E1DA274EDEBFE76F65FBD51AD2F14898B95B",
SHA384Util.encodeUpperCase(""));
}

@Test
public void encode(){
assertEquals(
"0a989ebc4a77b56a6e2bb7b19d995d185ce44090c13e2984b7ecc6d446d4b61ea9991b76a4c2f04b1b4d244841449454",
SHA384Util.encode("123456"));
assertEquals(
"38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b",
SHA384Util.encode(""));
}

//---------------------------------------------------------------

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.feilong.security.oneway;
package com.feilong.security.oneway.sha384;

import static org.junit.Assert.assertEquals;

Expand All @@ -24,8 +24,9 @@
import com.feilong.io.InputStreamUtil;
import com.feilong.lib.codec.digest.DigestUtils;
import com.feilong.security.AbstractSecurityTest;
import com.feilong.security.oneway.SHA384Util;

public class SHA384UtilTest extends AbstractSecurityTest{
public class Sha384EncodeFileTest extends AbstractSecurityTest{

@Test
public void encodeFile() throws IOException{
Expand All @@ -34,16 +35,6 @@ public void encodeFile() throws IOException{
assertEquals(encodeFile, DigestUtils.sha384Hex(InputStreamUtil.getInputStream(LOCATION)));
}

@Test
public void encode121(){
assertEquals(DigestUtils.sha384Hex("2284208963"), SHA384Util.encode("2284208963"));
}

@Test
public void encode12(){
LOGGER.debug(debugSecurityValue(SHA384Util.encode("2284208963")));
}

//---------------------------------------------------------------

@Test(expected = NullPointerException.class)
Expand All @@ -60,5 +51,4 @@ public void testSHA384UtilTestEmpty(){
public void testSHA384UtilTestBlank(){
SHA384Util.encodeFile(" ");
}

}

0 comments on commit 6a89785

Please sign in to comment.