ASP. NET (C #)-connect JAVA to RSA encrypted signatures-Lecture 3, asp.net
In this chapter, let's take a look at how Java implements RSA encryption.
Ah? Why? If you want to compare the differences, you have to see how people encrypt them.
Previously, I only talked about how to implement RSA encryption and decryption and signature verification in C #. Java only talked about how to generate a pem-format public key private key and how to convert it, however, the notes for Java and C # signatures are not explained, especially the connection.
Here we will talk about the origin of this article. It connects to a project. The program of the other company is written in java, and the program of our company is written in C #. The program provided by the other Party is in the Demo. NET program could not run normally, so I found the other technical staff to provide available examples to connect to the Demo, the other technical staff came up with a sentence "I don't understand.. NET ". No problem. I don't know Java either. I know the pain. So in order not to let more people suffer, I wrote this article.
Here we provide a piece of Java code to implement RSA Signature (really difficult, for a base64 transcoding, I searched for a morning solution)
The arrow indicates the algorithm used for signing. in C #, there is no such method as "MD5WithRSA". Therefore, a reference table is provided here, the relationship between the help classes using the encryption I wrote.
Java Signature |
C #/. NET (select Signature enumeration) |
MD5WithRSA |
EncryptType. MD5 |
SHA1WithRSA |
EncryptType. SHA1 |
SHA256WithRSA |
EncryptType. SHA256 |
SHA384WithRSA |
EncryptType. SHA384 |
SHA512 WithRSA |
EncryptType. SHA512 |
Signature Verification Code: (the correspondence is shown in the table above)
By the way, we provide the following methods to implement RSA encryption in Java:
Load the private key of the public key (the private key is used for signature, and I forgot to write it ...):
Implement encryption and decryption (public key encryption and Private Key decryption ):
Test method:
Use the Java code to encrypt and then decrypt it in C #.
Use Java to sign the data, and then use C # To verify the signature.
Note that the key should not be confused during the process. Here, the PCKS8 padding encryption is used in Java, so remember to convert the key generated in C # To the PCKS8 padding mode first.