mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
SM2.signHex改名为signHexFromHex,原名标记废弃,避免歧义
This commit is contained in:
@@ -324,10 +324,46 @@ public class SM2 extends AbstractAsymmetricCrypto<SM2> {
|
||||
* @param dataHex 被签名的数据数据
|
||||
* @return 签名
|
||||
*/
|
||||
public String signHexFromHex(String dataHex) {
|
||||
return signHex(dataHex, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用私钥对信息生成数字签名
|
||||
*
|
||||
* @param dataHex 被签名的数据数据
|
||||
* @return 签名
|
||||
* @deprecated 歧义,使用{@link #signHexFromHex(String)}
|
||||
*/
|
||||
@Deprecated
|
||||
public String signHex(String dataHex) {
|
||||
return signHex(dataHex, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用私钥对信息生成数字签名
|
||||
*
|
||||
* @param dataHex 被签名的数据数据
|
||||
* @param idHex 可以为null,若为null,则默认withId为字节数组:"1234567812345678".getBytes()
|
||||
* @return 签名
|
||||
*/
|
||||
public String signHexFromHex(String dataHex, String idHex) {
|
||||
return HexUtil.encodeHexStr(sign(HexUtil.decodeHex(dataHex), HexUtil.decodeHex(idHex)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 用私钥对信息生成数字签名
|
||||
*
|
||||
* @param dataHex 被签名的数据数据
|
||||
* @param idHex 可以为null,若为null,则默认withId为字节数组:"1234567812345678".getBytes()
|
||||
* @return 签名
|
||||
* @deprecated 歧义,使用{@link #signHexFromHex(String, String)}
|
||||
*/
|
||||
@Deprecated
|
||||
public String signHex(String dataHex, String idHex) {
|
||||
return HexUtil.encodeHexStr(sign(HexUtil.decodeHex(dataHex), HexUtil.decodeHex(idHex)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 用私钥对信息生成数字签名,签名格式为ASN1<br>
|
||||
* * 在硬件签名中,返回结果为R+S,可以通过调用{@link cn.hutool.crypto.SmUtil#rsAsn1ToPlain(byte[])}方法转换之。
|
||||
@@ -339,17 +375,6 @@ public class SM2 extends AbstractAsymmetricCrypto<SM2> {
|
||||
return sign(data, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用私钥对信息生成数字签名
|
||||
*
|
||||
* @param dataHex 被签名的数据数据
|
||||
* @param idHex 可以为null,若为null,则默认withId为字节数组:"1234567812345678".getBytes()
|
||||
* @return 签名
|
||||
*/
|
||||
public String signHex(String dataHex, String idHex) {
|
||||
return HexUtil.encodeHexStr(sign(HexUtil.decodeHex(dataHex), HexUtil.decodeHex(idHex)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 用私钥对信息生成数字签名,签名格式为ASN1<br>
|
||||
* 在硬件签名中,返回结果为R+S,可以通过调用{@link cn.hutool.crypto.SmUtil#rsAsn1ToPlain(byte[])}方法转换之。
|
||||
|
@@ -160,7 +160,7 @@ public class SM2Test {
|
||||
|
||||
final SM2 sm2 = SmUtil.sm2();
|
||||
|
||||
String sign = sm2.signHex(HexUtil.encodeHexStr(content));
|
||||
String sign = sm2.signHexFromHex(HexUtil.encodeHexStr(content));
|
||||
boolean verify = sm2.verifyHex(HexUtil.encodeHexStr(content), sign);
|
||||
assertTrue(verify);
|
||||
}
|
||||
|
Reference in New Issue
Block a user