ASP. NET (C #)-connect JAVA to RSA encrypted signatures-Lecture 3, asp.net

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.