mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
identity(without persist & without test)
This commit is contained in:
1 parent
9d370a5353
commit
755ddc2129
21 files changed
+588
-144
No files matched your search
@@ -4,7 +4,6 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import minsecurity.Common;
|
||||
import minsecurity.crypto.*;
|
||||
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
@@ -70,7 +69,7 @@ public class CertUtils {
|
||||
|
||||
certificate.setVersion(i.getTbsCertificate().getVersion());
|
||||
certificate.setSerialNumber(i.getTbsCertificate().getSerialNumber());
|
||||
PublicKeyInterface publicKey = PublicKeyUtils.unMarshalPublicKey(i.getTbsCertificate().getPublicKey(),i.getSignatureAlgorithm());
|
||||
PublicKeyInterface publicKey = KeyUtils.unMarshalPublicKey(i.getTbsCertificate().getPublicKey(),i.getSignatureAlgorithm());
|
||||
certificate.setPublicKey(publicKey);
|
||||
certificate.setSignature(i.getSignatureValue());
|
||||
certificate.setSignatureAlgorithm(i.getTbsCertificate().getSignatureAlgorithm());
|
||||
@@ -250,23 +249,17 @@ public class CertUtils {
|
||||
byte[] bytesOfCert = serialization(CertUtils.parseCertToInnerCert(certificate));
|
||||
byte[] ret;
|
||||
if(passwd != null && passwd.length > 0){
|
||||
byte[] hashPasswd = HashAlgo.sm3(passwd);
|
||||
if( hashPasswd.length == 32){
|
||||
for(int i = 0; i < 16; i++){
|
||||
hashPasswd[i] += hashPasswd[i + 16];
|
||||
}
|
||||
}
|
||||
byte[] sm4Key = new byte[16];
|
||||
System.arraycopy(hashPasswd,0,sm4Key,0,16);
|
||||
// byte[] sm4Key;
|
||||
byte[] sm4Key = KeyUtils.get16bytePasswd(passwd);
|
||||
|
||||
switch (symAlgoMode){
|
||||
case Common.SM4CBC:{
|
||||
// TODO: PADDING??? IV?????
|
||||
ret = Sm4.encrypt_CBC_Padding(sm4Key, new byte[16],bytesOfCert);
|
||||
ret = SM4.encrypt_CBC_Padding(sm4Key, new byte[16],bytesOfCert);
|
||||
break;
|
||||
}
|
||||
case Common.SM4ECB:{
|
||||
ret = Sm4.encrypt_ECB_Padding(sm4Key, bytesOfCert);
|
||||
ret = SM4.encrypt_ECB_Padding(sm4Key, bytesOfCert);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -294,21 +287,13 @@ public class CertUtils {
|
||||
byte[] bytesOfPem = Base64.getDecoder().decode(pemString);
|
||||
byte[] bytesOfCert = new byte[0];
|
||||
if(passwd != null && passwd.length > 0){
|
||||
byte[] hashPasswd = HashAlgo.sm3(passwd);
|
||||
if( hashPasswd.length == 32){
|
||||
for(int i = 0; i < 16; i++){
|
||||
hashPasswd[i] += hashPasswd[i + 16];
|
||||
}
|
||||
}
|
||||
byte[] sm4Key = new byte[16];
|
||||
System.arraycopy(hashPasswd,0,sm4Key,0,16);
|
||||
|
||||
byte[] sm4Key = KeyUtils.get16bytePasswd(passwd);
|
||||
switch (symAlgoMode){
|
||||
case Common.SM4CBC:
|
||||
bytesOfCert = Sm4.decrypt_CBC_Padding(sm4Key,new byte[16], bytesOfPem);
|
||||
bytesOfCert = SM4.decrypt_CBC_Padding(sm4Key,new byte[16], bytesOfPem);
|
||||
break;
|
||||
case Common.SM4ECB:
|
||||
bytesOfCert = Sm4.decrypt_ECB_Padding(sm4Key, bytesOfPem);
|
||||
bytesOfCert = SM4.decrypt_ECB_Padding(sm4Key, bytesOfPem);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user