Load a RSA private key in Java (algid parse error, not a sequence)

后端 未结 6 1639
夕颜
夕颜 2020-12-08 05:00

I\'m trying to load a private RSA key generated with ssl into java, my code is:

Generate the key:

openssl genrsa -out mykey.pem 1024         


        
6条回答
  •  一向
    一向 (楼主)
    2020-12-08 05:18

    Alternately you can conver your mykey.pem to DER format and use your existing code. Following is the openssl command to do that

     
    openssl pkcs8 -topk8 -inform PEM -outform DER -in mykey.pem -out mykey.der -nocrypt
    

    The new formatted file will look some thing like

     
    
    3082 0276 0201 0030 0d06 092a 8648 86f7
    0d01 0101 0500 0482 0260 3082 025c 0201
    0002 8181 00a9 0689 7676 2a63 5779 e4e8
    4bb5 8e53 bc44 a975 8254 cb64 5cf2 1499
    ad1c 6c35 6027 e357 ac09 0421 2b4b ddb4
    1be3 a688 a848 5618 bce8 25d0 2cf2 972b
    3801 a023 d6ee d824 4cfb 078f dad8 4317
    fc9d 9468 27cc 2f08 f755 3293 76cb 3c60
    4302 1c59 a8e8 5ac9 0576 8bb0 6bbb 8f1a
    092d 7884 a405 c775 a8ca 7a2c 8037 435c
    557a c9f0 a702 0301 0001 0281 8100 8462
    6c53 ee25 30fd 98a9 230f f939 6a78 30c7
    1114 6d59 8858 0bfa fa8a 4d92 ab13 8eea
    4f06 9d61 30a1 7aa0 40aa ff58 b5fc 27fb
    d710 4e3b 1f9b b4bd 95ca 1deb d165 063a
    da5c 383d e428 cbf6 1f62 4549 5b96 ee2d
    b811 4cff c849 9637 67e4 a5d5 1c75 f13b
    8ffffd b212 ba2f 7118 885e bc98 cab6 5434
    d1e8 2a33 c408 1186 be05 6074 7431 0241
    00d8 a1e2 d382 d52a 372e 0a62 807f 8283
    e615 c7a7 180b e21c b6ce cd55 940f 542b
    903f 86a0 e488 74b2 d69d d5d1 27d9 4079
    72a2 80f8 c105 3e19 309b dd78 4dbe 440d
    0d02 4100 c7bd e5fd ccee 60b2 cbc0 7520
    53c1 6442 9f11 e0d0 969f 6315 41cd 7b3c
    c279 cebe 4025 a4f4 97c9 6d1b c48f 6f01
    cd3b e849 33e6 5f13 7fb6 2780 22d1 f2da
    
     

提交回复
热议问题