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]