Guest User

Untitled

a guest
Aug 10th, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. //Wywołanie metod do utworzenia klucza szyfrowania
  2. private void CreateKey()
  3.         {
  4.             aesEncryptor = CreateEncryptor();
  5.             var based64Key = Convert.ToBase64String(aesEncryptor.Key);
  6.             var encryptedKey = EncryptRSA(based64Key);
  7.             jpkMetaData.encryptionKey = Convert.ToBase64String(encryptedKey);
  8.         }
  9.  
  10.  
  11. //Konstruktor szyfratora      
  12. private RijndaelManaged CreateEncryptor()
  13.         {
  14.             var myEncryptor = new RijndaelManaged();
  15.             myEncryptor.KeySize = 256;
  16.             myEncryptor.GenerateIV();
  17.             myEncryptor.GenerateKey();
  18.             return myEncryptor;
  19.         }
  20.  
  21. //Szyfrowanie pliku        
  22. private byte[] EncryptRSA(string plainText)
  23.         {
  24.             byte[] toEncrypt = Encoding.UTF8.GetBytes(plainText);
  25.  
  26.             string pathToSecurityFolder = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "Security");
  27.             X509Certificate2 cert = new X509Certificate2(pathToSecurityFolder + @"\3af5843ae11db6d94edf0ea502b5cd1a.pem");
  28.  
  29.             var RSACryptor = (RSACryptoServiceProvider) cert.PublicKey.Key;
  30.  
  31.             return RSACryptor.Encrypt(toEncrypt, false);
  32.         }
Advertisement
Add Comment
Please, Sign In to add comment