RSA


SUBMITTED BY: Guest

DATE: May 19, 2013, 3:57 a.m.

FORMAT: C#

SIZE: 1.2 kB

HITS: 2287

  1. String msgString = Systematic.GetFileContents(messagePath);
  2. Byte[] initVector = new byte[] { 50, 60, 70, 80, 90, 40, 50, 60, 70, 80, 90, 40, 60, 80, 70, 90 };
  3. Byte[] symetricKey = AesCrypt.GenerateRandomKey();
  4. Byte[] encryptedMessage = AesCrypt.Encrypt(msgString, symetricKey, initVector, mode);
  5. Byte[] modulus = null;
  6. Byte[] publicExp = null;
  7. DataFormatHelper.ReadPublicKey(publicKeyPath, "RSA", ref modulus, ref publicExp);
  8. static public byte[] RSAEncrypt(byte[] data,
  9. RSAParameters keyInfo,
  10. bool doOAEPPadding)
  11. {
  12. byte[] encryptedData;
  13. using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
  14. {
  15. //Import the RSA Key information. This only needs
  16. //toinclude the public key information.
  17. rsa.ImportParameters(keyInfo);
  18. //Encrypt the passed byte array and specify OAEP padding.
  19. //OAEP padding is only available on Microsoft Windows XP or later.
  20. encryptedData = rsa.Encrypt(data, doOAEPPadding);
  21. }
  22. return encryptedData;
  23. }

comments powered by Disqus