<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Sure:<div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">     </span><span style="color: #a1006a">public</span> <span style="color: #a1006a">void</span> generate () <span style="color: #a1006a">throws</span> IOException, NoSuchAlgorithmException</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">       </span>{</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(99, 0, 255); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">           </span>Q.println(</span>"Generating 2048 bit RSA Key... "<span style="color: #000000">);</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">           </span>KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(<span style="color: #6300ff">"RSA"</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">             </span>keyPairGenerator.initialize(2048);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">               </span>KeyPair keyPair = keyPairGenerator.genKeyPair();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">         </span><span style="color: #3c00d3">privateKey</span> = keyPair.getPrivate();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">             </span><span style="color: #3c00d3">publicKey</span> = keyPair.getPublic();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(99, 0, 255); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">          </span>Q.println(</span>"PrivateKey will be encoded using: "<span style="color: #000000"> + </span><span style="color: #3c00d3">privateKey</span><span style="color: #000000">.getFormat());</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(99, 0, 255); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">              </span>Q.println(</span>"KEY START -----------------------"<span style="color: #000000">);</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">         </span>Q.println(<span style="color: #a1006a">new</span> String(Base64.encode(<span style="color: #3c00d3">privateKey</span>.getEncoded())));</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(99, 0, 255); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">          </span>Q.println(</span>"KEY END -----------------------"<span style="color: #000000">);</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(99, 0, 255); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">              </span>Q.println(</span>"PublicKey will be encoded using: "<span style="color: #000000"> + </span><span style="color: #3c00d3">publicKey</span><span style="color: #000000">.getFormat());</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(99, 0, 255); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">                </span>Q.println(</span>"KEY START -----------------------"<span style="color: #000000">);</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">         </span>Q.println(<span style="color: #a1006a">new</span> String(Base64.encode(<span style="color: #3c00d3">publicKey</span>.getEncoded())));</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(99, 0, 255); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">           </span>Q.println(</span>"KEY END -----------------------"<span style="color: #000000">);</span></div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; min-height: 15.0px"><span class="Apple-tab-span" style="white-space:pre">              </span><br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">              </span>Q.println(<span style="color: #6300ff">"Done"</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">   </span>}</div><div><br></div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; ">Generating 2048 bit RSA Key... </div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; ">PrivateKey will be encoded using: PKCS#8</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; ">KEY START -----------------------</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; ">MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDlbI+Qa2zUwSRki7iTrcog4Zu0hrrx6jGlrC+xTsMfRj/gGA5npOBziSQMmqR6zhuVTR/9OAk5lX5muGQ2NdsngwE0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YQzbrkQQwOXeOr1mcRgbzovt1L2/XiUi/sC8BDkEKSNpW/YecaVmzyKYVX0gEuLYM33HkRNAoGBAM1HOZb79AEdG1fcFxVY6+OvzBTuEoKAEgxhrPqJ9b98CK/em6bxg7nTFh+T4/HHfl2aH5OOBHrx4eVKRfNh5XuokfaGgGpYYhHTz+UtaHrh9BDi+Ru1so8snx1ogAaGWiKCnH7wFAd6Zvkz4XOwHgndTMqrie5wdc4t2IzhAu8RAoGAEty14w80Zu2Yxady/YYDtdlOopAAh+D348gwC3Tw6RS+v1Awoc39arDRJWogQCFWNs5E00l10Dp5eOTgk8OLOA6PJJnFFpdr1Xs5H9O6ZAHac/bxsPtGehaRkAskurrbLSywdOJbQhf25xtdCO5ABwI66GgX5ojjzgB00fcyQDY=</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; ">KEY END -----------------------</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; ">PublicKey will be encoded using: X.509</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; ">KEY START -----------------------</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; ">MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5WyPkGts1MEkZIu4k63KIOGbtIa68eoxpawvsU7DH0Y/4BgOZ6Tgc4kkDJqkes4blU0f/TgJOZV+ZrhkNjXbJ4MBNIJe/N6o5EBb0DZEAwh/LSuqIgvpVSki2FGue3/b7rAjlNXpatz0wn1gFNJslefSYtmL1+rsaYu21ngcdcpiaKH0WkJQLqXTLl3EWi5AOKLXZTCxzuj0R9Vw83zLg/1ngxG2w6d0a5JthBJdgpPUwmOxi8A+vsSVAODpNhUIJmUNLqpP9HBg1SWuq8Z5UVjYOCrPFLeb6hXxBURnel7sW2Jr+reGLHjqMPntNHHe2A29dMv+Xl9fV/NFmEd7oQIDAQAB</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; ">KEY END -----------------------</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; ">Done</div></div><div><br></div><div>Hmm if this doesn't format, I'll try attaching a file.</div><div><br></div><div><br></div><div><br></div><div>I am checking my code over and over for some typo, the public key loads fine.</div><div><br></div><div>-tim</div><div><br></div><div><br><div><div>On Jul 24, 2012, at 2:58 PM, Jack Lloyd wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><br>The code looks plausible. Can you post an example key from the Java side?<br><br>On Tue, Jul 24, 2012 at 02:52:45PM -0400, Timothy Prepscius wrote:<br><blockquote type="cite">ok, so I think I have a pkcs8 encoded private key.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">The java code looks like this:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">new String(Base64.encode(privateKey.getEncoded()));<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">where privateKey was generated with:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");<br></blockquote><blockquote type="cite">keyPairGenerator.initialize(2048);<br></blockquote><blockquote type="cite">KeyPair keyPair = keyPairGenerator.genKeyPair();<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">the <br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">privateKey.getFormat()<br></blockquote><blockquote type="cite">says: PKCS#8<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">----------------------------------------<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I'm trying to get that private key into botan.<br></blockquote><blockquote type="cite">It would be best if I could do it without changing the java code.  But that is an option if all else fails :-)<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I was trying code like this:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">  </span>if (!privateKey.empty())<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">       </span>{<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">      </span><span class="Apple-tab-span" style="white-space:pre">    </span>AutoSeeded_RNG rng;<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">    </span><span class="Apple-tab-span" style="white-space:pre">    </span>Block key = fromBase64(privateKey);<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">    </span><span class="Apple-tab-span" style="white-space:pre">    </span>Botan::DataSource_Memory dataSource((const unsigned char *)key.data(), (Botan::u32bit)key.size());<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">     </span><span class="Apple-tab-span" style="white-space:pre">    </span>Botan::PKCS8_PrivateKey *genericPrivateKey = Botan::PKCS8::load_key(dataSource, rng);<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">     </span><span class="Apple-tab-span" style="white-space:pre">    </span>Botan::RSA_PrivateKey *rsaPrivateKey = <br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">    </span><span class="Apple-tab-span" style="white-space:pre">    </span>dynamic_cast<Botan::RSA_PrivateKey *> (<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">  </span><span class="Apple-tab-span" style="white-space:pre">    </span><span class="Apple-tab-span" style="white-space:pre">    </span><span class="Apple-tab-span" style="white-space:pre">    </span>genericPrivateKey<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">      </span><span class="Apple-tab-span" style="white-space:pre">    </span><span class="Apple-tab-span" style="white-space:pre">    </span>);<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">     </span><span class="Apple-tab-span" style="white-space:pre">    </span><span class="Apple-tab-span" style="white-space:pre">    </span><br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">       </span><span class="Apple-tab-span" style="white-space:pre">    </span>privateKeyImpl = rsaPrivateKey;<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre">        </span>}<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">But of course, I think that the format is completely different, not sure, actually.<br></blockquote><blockquote type="cite">And it throws a decoding exception<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Any thoughts?<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">-tim<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><br><blockquote type="cite">_______________________________________________<br></blockquote><blockquote type="cite">botan-devel mailing list<br></blockquote><blockquote type="cite"><a href="mailto:botan-devel@randombit.net">botan-devel@randombit.net</a><br></blockquote><blockquote type="cite"><a href="http://lists.randombit.net/mailman/listinfo/botan-devel">http://lists.randombit.net/mailman/listinfo/botan-devel</a><br></blockquote><br>_______________________________________________<br>botan-devel mailing list<br><a href="mailto:botan-devel@randombit.net">botan-devel@randombit.net</a><br>http://lists.randombit.net/mailman/listinfo/botan-devel<br></div></blockquote></div><br></div></div></body></html>