相关疑难解决方法(0)

带有Bouncy Castle的256位AES/CBC/PKCS5Padding

我无法将以下JDK JCE加密代码映射到Bouncy Castles Light-weight API:

public String dec(String password, String salt, String encString) throws Throwable {
    // AES algorithm with CBC cipher and PKCS5 padding
    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC");

    // Construct AES key from salt and 50 iterations 
    PBEKeySpec pbeEKeySpec = new PBEKeySpec(password.toCharArray(), toByte(salt), 50, 256);
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithSHA256And256BitAES-CBC-BC");
    SecretKeySpec secretKey = new SecretKeySpec(keyFactory.generateSecret(pbeEKeySpec).getEncoded(), "AES");

    // IV seed for first block taken from first 32 bytes
    byte[] ivData = toByte(encString.substring(0, 32));
    // AES encrypted data
    byte[] encData = …
Run Code Online (Sandbox Code Playgroud)

java cryptography bouncycastle aes

13
推荐指数
1
解决办法
5万
查看次数

标签 统计

aes ×1

bouncycastle ×1

cryptography ×1

java ×1