rsa - Signing and verifying data with Java won't work -


i created rsa key pair (plus self-signed certificate) openssl using following command:

openssl req -x509 -newkey rsa:2048 -keyout privado-ssl.pem -out certificado-ssl.pem -days 365 -nodes 

the name of generated files , contents are:

privado-ssl.pem:

-----begin rsa private key----- miiepaibaakcaqea45ttncik6tomf6pgfczhnyx8xlqkwuylf0kyvnjihn+h1wp9 tyhbjw9xsszopw4riwgudidmdh0gltvm0axieyjt2gzdfoyh+o9zd2+kmpofwhfu (etc, etc...) -----end rsa private key----- 

certificado-ssl.pem:

-----begin certificate----- miiemdcca4cgawibagijaompp5khpi+wma0gcsqgsib3dqebbquamigomqswcqyd vqqgewjqrtenmasga1uecbmetgltytenmasga1uebxmetgltytetmbega1uechmk tm92yxryb25pyzemmaoga1uecxmdq0fumrgwfgydvqqdew9eyw5pzwwgq2fszgvy (etc, etc ...) -----end certificate----- 

since i'm using java.security.* classes sign , verify signature, transformed privado-ssl.pem (my private key) pksc8 format , der enconding using:

openssl pkcs8 -topk8 -outform der -in privado-ssl.pem -out privado-ssl-pkcs8-der.pem -nocrypt 

but, when using said classes verify signature false when verifying signature (but no exception).

this way private key private key file (as byte array):

keyfactory keyfactory = keyfactory.getinstance("rsa"); keyspec privatekeyspec = new pkcs8encodedkeyspec(privatekeybytes); return keyfactory.generateprivate(privatekeyspec); 

and certificate:

inputstream certificateinputstream = new bytearrayinputstream(certificatebytes); certificatefactory certificatefactory = certificatefactory.getinstance("x.509"); return certificatefactory.generatecertificates(certificateinputstream).get(0); 

for signing , verifying, i'm using sha1withrsa algorithm no provider.

what can possibly doing wrong? please, if need more information let me know. desperate here :)


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -