[botan-devel] java pkcs8 encoding -> botan

Timothy Prepscius timprepscius at gmail.com
Tue Jul 24 14:55:15 EDT 2012


I should also mention that I'm using botan installed via port install

botan                          @1.8.13         security/botan

-tim

On Jul 24, 2012, at 2:52 PM, 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
> 
> 
> 

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


More information about the botan-devel mailing list