fix:兼容go版本的sm2

This commit is contained in:
ChessNineeee committed 2021-04-12 17:33:15 +08:00
1 parent 74358fbc5e
commit f69ab1703e
5 files changed
+103 -55

No files matched your search

@@ -177,5 +177,43 @@ public class SM2Base {
return SM2KeyPair.generateKeyPair();
}
/**
* SM2字节数组->16进制字节数组 辅助函数
* @param bytes byte[]
* @return byte[]
* @throws
* @author zhengqi wu
* @date 2021/4/12
**/
public static byte[] byteArraytoHexByteArray(byte[] bytes){
// 16进制表示法
StringBuilder sb = new StringBuilder();
for(int i=0;i < bytes.length;i++) {
sb.append(String.format("%02x", bytes[i]));
}
String hexStr = sb.toString();
return hexStr.getBytes();
}
/**
* 16进制字节数组->SM2字节数组 辅助函数
* @param bytes byte[]
* @return byte[]
* @throws
* @author zhengqi wu
* @date 2021/4/12
**/
public static byte[] hexByteArrayToByteArray(byte[] bytes){
String hex = new String(bytes);
if (hex.length() < 1) {
return null;
} else {
byte[] result = new byte[hex.length() / 2];
int j = 0;
for(int i = 0; i < hex.length(); i+=2) {
result[j++] = (byte)Integer.parseInt(hex.substring(i,i+2), 16);
}
return result;
}
}
}