I have read this topic, it''s wonderful.:thumbsup:
But I just have a reverse process about of this topic. The keys (public and private) were generated by .Net platform, I want to decode the public key to encrypt a text and then send it back to the .Net platform to decrypt it.
I can not convert the string of public key to Java public key. I have found many materials and it looks like the string of public key was generated with some random value by .Net platform.
What should I do with the string?
Thanks.
Below is the errors when I try to get the public key:Exception in thread "main" java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException: DerInputStream.getLength(): lengthTag=82, too big.
at sun.security.rsa.RSAKeyFactory.engineGeneratePublic(RSAKeyFactory.java:188)
at java.security.KeyFactory.generatePublic(KeyFactory.java:304)
at Test.main(Test.java:55)
Caused by: java.security.InvalidKeyException: IOException: DerInputStream.getLength(): lengthTag=82, too big.
at sun.security.x509.X509Key.decode(X509Key.java:380)
at sun.security.x509.X509Key.decode(X509Key.java:386)
at sun.security.rsa.RSAPublicKeyImpl.(RSAPublicKeyImpl.java:66)
at sun.security.rsa.RSAKeyFactory.generatePublic(RSAKeyFactory.java:281)
at sun.security.rsa.RSAKeyFactory.engineGeneratePublic(RSAKeyFactory.java:184)
... 2 more
解决方案
Don''t post this under Quick Answers - if you got the code from an article, then there is a "new message" button at the bottom of that article, which causes an email to be sent to the author. They are then alerted that you wish to speak to them. If it is a topic in a forum, then the "Reply" link at the bottom of the topic does the same thing.
Posting this here relies on them "dropping by" and realising it is for them.