RSA encryption and decryption and Signature Verification

Source: Internet
Author: User

For rsacryption help class definition, see rsacryption

I. encryption and decryption

// Define the plaintext and ciphertext variables string plaintext = "Tiandao rewards, good deeds! "; String ciphertext =" "; // generate the key string prikey =" ", pubkey =" "; RSA. rsakey (Out prikey, out pubkey); // the encryption and decryption process: ciphertext = RSA. rsaencrypt (pubkey, plaintext); plaintext = RSA. rsadecrypt (prikey, ciphertext );
View code

 

Ii. Signature and Verification

// Obtain the plaintext hash value byte [] plaintexthash = NULL; RSA. gethash (plaintext, ref plaintexthash); // obtain the signed ciphertext string signatureciphertext = NULL; RSA. signatureformatter (prikey, plaintexthash, ref signatureciphertext); // verify string verify = RSA. signaturedeformatter (pubkey, plaintexthash, signatureciphertext )? "OK! No problem ":" No! The content has been tampered ";
View code

 

Tips: Using the RSA signature and verification function, you can also simply implement the software registration code function. The signature is the registration code, and the verification is the verification.

Related Links

RSA segmented encryption [solves the "incorrect length" exception]

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.