张洋洋
2025-01-14 1ad7b12d159e4b69e8c23670e64de1700e2c8ed4
src/main/java/com/se/simu/helper/RsaHelper.java
@@ -137,4 +137,17 @@
        return outStr;
    }
    public static String encrypt(String key, String str) throws Exception {
        byte[] decoded = Base64.decodeBase64(key);
        RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));
        Cipher cipher = Cipher.getInstance("RSA");
        cipher.init(Cipher.ENCRYPT_MODE, pubKey);
        String outStr = Base64.encodeBase64String(cipher.doFinal(str.getBytes(StandardCharsets.UTF_8)));
        return outStr;
    }
}