Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Wywołanie metod do utworzenia klucza szyfrowania
- private void CreateKey()
- {
- aesEncryptor = CreateEncryptor();
- var based64Key = Convert.ToBase64String(aesEncryptor.Key);
- var encryptedKey = EncryptRSA(based64Key);
- jpkMetaData.encryptionKey = Convert.ToBase64String(encryptedKey);
- }
- //Konstruktor szyfratora
- private RijndaelManaged CreateEncryptor()
- {
- var myEncryptor = new RijndaelManaged();
- myEncryptor.KeySize = 256;
- myEncryptor.GenerateIV();
- myEncryptor.GenerateKey();
- return myEncryptor;
- }
- //Szyfrowanie pliku
- private byte[] EncryptRSA(string plainText)
- {
- byte[] toEncrypt = Encoding.UTF8.GetBytes(plainText);
- string pathToSecurityFolder = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "Security");
- X509Certificate2 cert = new X509Certificate2(pathToSecurityFolder + @"\3af5843ae11db6d94edf0ea502b5cd1a.pem");
- var RSACryptor = (RSACryptoServiceProvider) cert.PublicKey.Key;
- return RSACryptor.Encrypt(toEncrypt, false);
- }
Advertisement
Add Comment
Please, Sign In to add comment