11
13693261870
2024-11-11 30cae3cbdea7dfb4d04b564ffd32dca8d70e94f3
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;
    }
}