rsa - Read encrypted PKCS8 SpongyCastle Java -
i following code in: https://stackoverflow.com/a/18161536/1753951 getting exception in following line:
fileinputstream fis = new fileinputstream(priv); datainputstream dis = new datainputstream(fis); byte[] keybytes = new byte[(int)priv.length()]; dis.readfully(keybytes); dis.close(); javax.crypto.encryptedprivatekeyinfo encryptpkinfo = new encryptedprivatekeyinfo(keybytes); //exception: org.apache.harmony.security.asn1.asn1exception: wrong content length
i trying read .key/.pem pkcs8 file is:
-----begin rsa private key----- proc-type: 4,encrypted dek info: aes-256-cbc,8aff348907c84f2f6370a216dc0d55d9 1vijjd3dz5/wynim0mtp8d22rc24ygcy9lxgehudbypjqa8pjupubfqkrpoodvqx dpfe1f3xey8ovg42zfr4287x4v16n++bqcediuvyrwaclmauqz6pflt4b/py89cm 761uzpawnh0phfjqb9chqc+pgagfrf5vj7utdnchcwbmo+7gvu5igyyxnrj/hpnu v+8qdzro4kfimoldzhaj3kn1ftbb9ldjdne/nshbrrafawjmzsy/zjf8mfqggkoz %%%%% skipped of %%%%%%%%%% bmil0y5xvgpwkapa30edgv4yazej+wqlnyizfcklqzvcfyjxhfvivw6d41wnm8bx wl28v4qjklnf7kncmmgwsmjko7beassz+xvyru0r6fae+job5yzprtui+p/kf7et y+judbz4bpvb8j2zscnrs+pjkexxpt5jkw/oqmqzplbttsv5k1iqiuvcri9tbczk nwdsfi/wxt6ck3x9xvyopozdcdpchkihdhczfitd7fzkm1vbekwslijwjgc1bwbc ni4ahqcnb8li7ox1m2osyer3zf25bdb2a04zm1lmrwkfrypb24dkksjxyeh33gpu -----end rsa private key-----
after looking long time solution stumbled library helps me , works on android. not-yet-commons
http://juliusdavies.ca/commons-ssl/
fileinputstream in = new fileinputstream( "/path/to/pkcs8_private_key.der" ); pkcs8key pkcs8 = new pkcs8key( in, "changeit".tochararray() ); byte[] decrypted = pkcs8.getdecryptedbytes(); pkcs8encodedkeyspec spec = new pkcs8encodedkeyspec( decrypted ); // java privatekey object born. privatekey pk = null; if ( pkcs8.isdsa() ) { pk = keyfactory.getinstance( "dsa" ).generateprivate( spec ); } else if ( pkcs8.isrsa() ) { pk = keyfactory.getinstance( "rsa" ).generateprivate( spec ); } // lazier types (like me): pk = pkcs8.getprivatekey();
Comments
Post a Comment