Export private key from java keystore (JKS)

I was working with one of my servers to add SSL support (PS, There is free SSL certificate being issued by CAs – and on the other hand, how dangerous the world is!). I generated the CSR using the java keytool with a JKS format. However, when I need to export the JKS file to a DER format for nginx, the keytool doesn’t have a way to export that. I have to develop something by myself and here’s the jython script.


import java
k=java.security.KeyStore.getInstance('jks')
k.load(java.io.FileInputStream('imdm.jks'),'weblogic')
p=k.getKey('imdm_key1','weblogic')
print ''.join([chr(0xff&x) for x in p.encoded]).encode('base64')