[botan-devel] java pkcs8 encoding -> botan

Jack Lloyd lloyd at randombit.net
Tue Jul 24 14:58:38 EDT 2012


The code looks plausible. Can you post an example key from the Java side?

On Tue, Jul 24, 2012 at 02:52:45PM -0400, Timothy Prepscius wrote:
> 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");
> keyPairGenerator.initialize(2048);
> KeyPair keyPair = keyPairGenerator.genKeyPair();
> 
> the 
> 
> privateKey.getFormat()
> 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 *> (
> 				genericPrivateKey
> 			);
> 			
> 		privateKeyImpl = rsaPrivateKey;
> 	}
> 
> 
> But of course, I think that the format is completely different, not sure, actually.
> And it throws a decoding exception
> 
> 
> Any thoughts?
> 
> -tim
> 
> 
> 

> _______________________________________________
> botan-devel mailing list
> botan-devel at randombit.net
> http://lists.randombit.net/mailman/listinfo/botan-devel




More information about the botan-devel mailing list