suerprisePlus
2024-09-03 2e9e03c7971f1da71cc9e9bd7d2f159c244839f3
src/main/java/com/yb/helper/RsaHelper.java
@@ -8,20 +8,20 @@
import java.security.spec.X509EncodedKeySpec;
public class RsaHelper {
//    RsA秘钥加密
public static String encrypt(String key ,String str) throws Exception {
    // Base64编码的公钥
    byte[] decoded = Base64.decodeBase64(key+ "");
    //    RsA秘钥加密
    public static String encrypt(String key, String str) throws Exception {
        // Base64编码的公钥
        byte[] decoded = Base64.decodeBase64(key + "");
    RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));
        RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));
    // RSA加密:RSA/ECB/NoPadding
    Cipher cipher = Cipher.getInstance("RSA");
    cipher.init(Cipher.ENCRYPT_MODE, pubKey);
        // RSA加密:RSA/ECB/NoPadding
        Cipher cipher = Cipher.getInstance("RSA");
        cipher.init(Cipher.ENCRYPT_MODE, pubKey);
    String outStr = Base64.encodeBase64String(cipher.doFinal(str.getBytes("UTF-8")));
        String outStr = Base64.encodeBase64String(cipher.doFinal(str.getBytes("UTF-8")));
    return outStr;
}
        return outStr;
    }
}