gpt4 book ai didi

java - 无法创建密码,没有这样的算法

转载 作者:行者123 更新时间:2023-11-30 08:38:29 24 4
gpt4 key购买 nike

我正在使用 BountyCaSTLe 使用算法 AES128_CBC 加密文件,代码如下:

static {
Provider provider = Security.getProvider (BouncyCastleProvider.PROVIDER_NAME);
if (provider == null) {
Security.addProvider (new BouncyCastleProvider ());
}
}

public static void main (String[] args) throws IOException, CertificateException, UnrecoverableKeyException, KeyStoreException,
NoSuchAlgorithmException, InvalidAlgorithmParameterException, NoSuchProviderException,
CertStoreException, CMSException, NoSuchPaddingException, InvalidKeyException,
ShortBufferException, IllegalBlockSizeException, BadPaddingException {

File f = new File ("ToBeEncrypted.txt");
byte[] buffer = new byte [(int)f.length ()];
DataInputStream in = new DataInputStream (new FileInputStream (f));
in.readFully (buffer);
in.close ();

X509Certificate cert = ReadX509.read (new FileInputStream ("test.cer"));

CMSEnvelopedDataGenerator gen = new CMSEnvelopedDataGenerator ();
RecipientInfoGenerator recipientGenerator = new JceKeyTransRecipientInfoGenerator (cert).setProvider ("BC");
gen.addRecipientInfoGenerator (recipientGenerator);

OutputEncryptor outputEncryptor = new JceCMSContentEncryptorBuilder (CMSAlgorithm.AES128_CBC).build ();
CMSEnvelopedData envData = gen.generate (new CMSProcessableByteArray (buffer), outputEncryptor);

byte[] pkcs7envelopedData = envData.getEncoded ();

FileOutputStream envfos = new FileOutputStream ("ToBeDecrypted.pk7");
envfos.write (pkcs7envelopedData);
envfos.close ();
}

但是,我一直有以下异常在线

CMSEnvelopedData envData = gen.generate (new CMSProcessableByteArray (buffer), outputEncryptor); :

Exception in thread "main" org.bouncycastle.cms.CMSException: exception wrapping content key: cannot create cipher: No such algorithm: 1.2.840.10040.4.1
at org.bouncycastle.cms.KeyTransRecipientInfoGenerator.generate(Unknown Source)
at org.bouncycastle.cms.CMSEnvelopedDataGenerator.doGenerate(Unknown Source)
at org.bouncycastle.cms.CMSEnvelopedDataGenerator.generate(Unknown Source)
at com.crypto.tests.EncryptDocument.main(EncryptDocument.java:74)

Caused by: org.bouncycastle.operator.OperatorCreationException: cannot create cipher: No such algorithm: 1.2.840.10040.4.1
at org.bouncycastle.operator.jcajce.OperatorHelper.createAsymmetricWrapper(Unknown Source)
at org.bouncycastle.operator.jcajce.JceAsymmetricKeyWrapper.generateWrappedKey(Unknown Source)
... 4 more

Caused by: java.security.NoSuchAlgorithmException: No such algorithm: 1.2.840.10040.4.1
at javax.crypto.Cipher.getInstance(Cipher.java:688)
at javax.crypto.Cipher.getInstance(Cipher.java:596)
at org.bouncycastle.jcajce.util.NamedJcaJceHelper.createCipher(Unknown Source)
... 6 more

有什么想法吗?

最佳答案

您不能使用 DSA 算法或 DSA key 进行加密(1.2.840.10040.4.1 是 DSA)。 DSA 代表数字签名 算法。尝试改用 RSA。

关于java - 无法创建密码,没有这样的算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36518988/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com