Click here to Skip to main content
15,917,645 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.<init>(RSAPublicKeyImpl.java:66)
	at sun.security.rsa.RSAKeyFactory.generatePublic(RSAKeyFactory.java:281)
	at sun.security.rsa.RSAKeyFactory.engineGeneratePublic(RSAKeyFactory.java:184)
	... 2 more</init>
Posted
Updated 17-Mar-10 23:16pm
v2

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900