public string Decrypt(EncryptedText cipherText) { byte[] cipherBytes = cipherText.GetBytes(); byte[] iv = cipherText.Iv; byte[] clearBytes = ProtectedData.Unprotect(cipherBytes, iv, DataProtectionScope.LocalMachine); return Encoding.UTF8.GetString(clearBytes); }
public string Decrypt(EncryptedText cipherText) { byte[] cipherBytes = cipherText.GetBytes(); byte[] iv = cipherText.Iv; byte[] clearBytes = ProtectedData.Unprotect(cipherBytes, iv, DataProtectionScope.LocalMachine); return(Encoding.UTF8.GetString(clearBytes)); }
public EncryptedText Encrypt(string clearText) { byte[] clearBytes = Encoding.UTF8.GetBytes(clearText); byte[] iv = GenerateIv(); byte[] cipherBytes = ProtectedData.Protect(clearBytes, iv, DataProtectionScope.LocalMachine); var result = new EncryptedText(cipherBytes, iv); return result; }
public EncryptedText Encrypt(string clearText) { byte[] clearBytes = Encoding.UTF8.GetBytes(clearText); byte[] iv = GenerateIv(); byte[] cipherBytes = ProtectedData.Protect(clearBytes, iv, DataProtectionScope.LocalMachine); var result = new EncryptedText(cipherBytes, iv); return(result); }
public string Decrypt(EncryptedText cipherText) { _cipher.IV = cipherText.Iv; using (ICryptoTransform transform = _cipher.CreateDecryptor()) { byte[] cipherBytes = cipherText.GetBytes(); byte[] clearBytes = transform.TransformFinalBlock(cipherBytes, 0, cipherBytes.Length); return(Encoding.UTF8.GetString(clearBytes)); } }
public string Decrypt(EncryptedText cipherText) { _cipher.IV = cipherText.Iv; using (ICryptoTransform transform = _cipher.CreateDecryptor()) { byte[] cipherBytes = cipherText.GetBytes(); byte[] clearBytes = transform.TransformFinalBlock(cipherBytes, 0, cipherBytes.Length); return Encoding.UTF8.GetString(clearBytes); } }