小编fik*_*Raf的帖子

AES使用Bouncy Castle提供商加密/解密

这是我使用JDK 5的本机库开发的AES 256加密和解密的实现:

public static String encrypt(String key, String toEncrypt) throws Exception {
    Key skeySpec = generateKeySpec(key);
    Cipher cipher = Cipher.getInstance("AES");
    cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
    byte[] encrypted = cipher.doFinal(toEncrypt.getBytes());
    byte[] encryptedValue = Base64.encodeBase64(encrypted);
    return new String(encryptedValue);
}

public static String decrypt(String key, String encrypted) throws Exception {
    Key skeySpec = generateKeySpec(key);
    Cipher cipher = Cipher.getInstance("AES");
    cipher.init(Cipher.DECRYPT_MODE, skeySpec);
    byte[] decodedBytes = Base64.decodeBase64(encrypted.getBytes());
    byte[] original = cipher.doFinal(decodedBytes);
    return new String(original);
}
Run Code Online (Sandbox Code Playgroud)

我想用Boucy Castle API(Java)实现相同的方法:我搜索了很多,测试了很多,没有结果......有人可以帮我吗?

谢谢

java cryptography bouncycastle aes

8
推荐指数
1
解决办法
4万
查看次数

标签 统计

aes ×1

bouncycastle ×1

cryptography ×1

java ×1