Jachept与Bouncy Castle JCE SHA512加密

时间:2015-04-08 07:37:13

标签: encryption bouncycastle jce sha512 jasypt

我需要: 使用sha512摘要的基于密码的加密和设置了cbc和bc标志的256位AES加密

似乎算法应该是这样的: PBEWithSHA512AndAES256-CBC-BC

但是在我的本地环境中我收到错误: org.jasypt.exceptions.EncryptionInitializationException:java.security.NoSuchAlgorithmException:没有这样的算法:提供者BC的PBEWithSHA512AndAES256-CBC-BC

我的测试代码:

import java.security.Security;

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;

public class App {

static {
    Security.addProvider(new BouncyCastleProvider());
}

public static void main(String[] args) {
    StandardPBEStringEncryptor mySecondEncryptor = new StandardPBEStringEncryptor();
    mySecondEncryptor.setProviderName("BC");
    // mySecondEncryptor.setAlgorithm("PBEWITHSHA256AND128BITAES-CBC-BC");
    mySecondEncryptor.setAlgorithm("PBEWithSHA512AndAES256-CBC-BC");
    mySecondEncryptor.setPassword("pass");

    String myText = "Mindaugas";
    String mySecondEncryptedText = mySecondEncryptor.encrypt(myText);

    System.out.println(mySecondEncryptedText);
    System.out.println(mySecondEncryptor.decrypt(mySecondEncryptedText));
}
}

PBEWITHSHA256AND128BITAES-CBC-BC - 这个算法工作正常,但我需要sha512和256位AES ......

我已安装扩展程序表单:http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html

但仍然会收到此错误:没有此类算法

1 个答案:

答案 0 :(得分:2)

由于bouncycastle website上的算法列表未更新,查看Java文件BouncyCastleProvider.java中构造函数中的代码,您可以找到bcprov支持的算法的详尽列表。 jdk16。支持的小列表(您正在寻找的算法/函数类型)是 -

PBEWITHSHAAND128BITAES-CBC-BC
PBEWITHSHAAND192BITAES-CBC-BC
PBEWITHSHAAND256BITAES-CBC-BC
PBEWITHSHA256AND128BITAES-CBC-BC
PBEWITHSHA256AND192BITAES-CBC-BC
PBEWITHSHA256AND256BITAES-CBC-BC
PBEWITHSHA1AND128BITAES-CBC-BC
PBEWITHSHA1AND192BITAES-CBC-BC
PBEWITHSHA1AND256BITAES-CBC-BC
PBEWITHSHA-1AND128BITAES-CBC-BC
PBEWITHSHA-1AND192BITAES-CBC-BC
PBEWITHSHA-1AND256BITAES-CBC-BC
PBEWITHSHA-256AND128BITAES-CBC-BC
PBEWITHSHA-256AND192BITAES-CBC-BC
PBEWITHSHA-256AND256BITAES-CBC-BC