"No such algorithm: 1.2.840.113549.1.5.13" occurs when creating an EncryptedPrivateKey instance.

Satoru Otsubo <trnsec-96mi//[email protected]> Tue, 6 Nov 2018 20:36:08 +0900
Newsgroups gmane.comp.encryption.bouncy-castle.devel
Message-ID <[email protected]>
Hi,

I made a self-signed certificate and produced an encrypted key.pem.
 by using the following command and entering a password:

 $ openssl req -x509 -newkey rsa:2048 -keyout key.pem -outform pem -out cert.pem -days 365

Then, I tried to make the javax.crypto.EncryptedPrivateKeyInfo instance from the above key.pem with the program below,
 by referring to org.bouncycastle.jce.provider.test.EncryptedPrivateKeyInfoTest.java
(I used jdk1.7.0_80 and ***-jdk15on-160.jar)

But "java.security.NoSuchAlgorithmException: No such algorithm: 1.2.840.113549.1.5.13" occured.

As there is also org.bouncycastle.asn1.pkcs.EncryptedPrivateKeyInfo, I tried to use it.

But even in this case,"java.security.NoSuchAlgorithmException: No such algorithm: 1.2.840.113549.1.5.13" occured.

I appreciate if anyone can explain why "No such algorithm: 1.2.840.113549.1.5.13" occurs.

Thanks in advance.

Satoru Otsubo

***************************************************************

import java.io.*;
import javax.crypto.Cipher;

import org.bouncycastle.util.io.pem.*;

public class EncryptedPrivateKeyInfoTest
{
	public static void main(String[] args)
		throws Exception
	{
		PemReader reader = new PemReader(new InputStreamReader(new FileInputStream("key.pem")));

		PemObject pemObj = reader.readPemObject();

		byte[] pemCntnt = pemObj.getContent();
		
		java.security.Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

		try {
			javax.crypto.EncryptedPrivateKeyInfo pInfo =
				new javax.crypto.EncryptedPrivateKeyInfo(pemCntnt);

			Cipher cipher = Cipher.getInstance(pInfo.getAlgName(), "BC");

		} catch (java.security.NoSuchAlgorithmException e) {

			e.printStackTrace();
		}

		try {
			org.bouncycastle.asn1.pkcs.EncryptedPrivateKeyInfo pInfo = 
				org.bouncycastle.asn1.pkcs.EncryptedPrivateKeyInfo.getInstance(pemCntnt);

			Cipher cipher = 
				Cipher.getInstance(pInfo.getEncryptionAlgorithm().getAlgorithm().getId(), "BC");

		} catch (java.security.NoSuchAlgorithmException e) {

			e.printStackTrace();
		}
	}
}

***************************************************************