[botan-devel] java pkcs8 encoding -> botan

Timothy Prepscius timprepscius at gmail.com
Tue Jul 24 14:52:45 EDT 2012

ok, so I think I have a pkcs8 encoded private key.

The java code looks like this:

new String(Base64.encode(privateKey.getEncoded()));

where privateKey was generated with:

KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
KeyPair keyPair = keyPairGenerator.genKeyPair();


says: PKCS#8


I'm trying to get that private key into botan.
It would be best if I could do it without changing the java code.  But that is an option if all else fails :-)

I was trying code like this:

	if (!privateKey.empty())
		AutoSeeded_RNG rng;
		Block key = fromBase64(privateKey);
		Botan::DataSource_Memory dataSource((const unsigned char *)key.data(), (Botan::u32bit)key.size());
		Botan::PKCS8_PrivateKey *genericPrivateKey = Botan::PKCS8::load_key(dataSource, rng);

		Botan::RSA_PrivateKey *rsaPrivateKey = 
			dynamic_cast<Botan::RSA_PrivateKey *> (
		privateKeyImpl = rsaPrivateKey;

But of course, I think that the format is completely different, not sure, actually.
And it throws a decoding exception

Any thoughts?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.randombit.net/pipermail/botan-devel/attachments/20120724/74d7a111/attachment.html>

More information about the botan-devel mailing list