Browse Source

修改逻辑

master
yechuan 1 year ago
parent
commit
7ad972a8ec
1 changed files with 6 additions and 4 deletions
  1. +6
    -4
      common/src/main/java/work/xuye/common/utils/signature/RSASignatureService.java

+ 6
- 4
common/src/main/java/work/xuye/common/utils/signature/RSASignatureService.java View File

@@ -8,7 +8,6 @@ import work.xuye.common.enums.SignatureEnumGroup;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.Signature;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
@@ -35,11 +34,12 @@ class RSASignatureService extends AbstractSignatureService {
@Override
public String signatureByPriKey(String content) throws GeneralSecurityException {
if (signatureContext == null) {
throw new RuntimeException("未初始化公私钥信息");
throw new RuntimeException("未初始化公私钥对信息");
}
if (signatureContext.getSignature() == null) {
throw new RuntimeException("未初始化私钥信息");
}
Signature signature = signatureContext.getSignature();
PrivateKey priKey = signatureContext.getPriKey();
signature.initSign(priKey);
content = DigestUtils.md5DigestAsHex(content.getBytes(StandardCharsets.UTF_8)).toUpperCase();
signature.update(content.getBytes(StandardCharsets.UTF_8));
return Base64.encodeBase64String(signature.sign());
@@ -58,10 +58,12 @@ class RSASignatureService extends AbstractSignatureService {

if (SignatureEnumGroup.KeyType.privateKey.equals(keyType)) {
signatureContext.setPriKey(keyFactory.generatePrivate(new PKCS8EncodedKeySpec(encodedKey)));
signatureContext.getSignature().initSign(signatureContext.getPriKey());
} else if (SignatureEnumGroup.KeyType.publicKey.equals(keyType)) {
signatureContext.setPubKey(keyFactory.generatePublic(new X509EncodedKeySpec(encodedKey)));
}


}




Loading…
Cancel
Save