public static byte[] Decrypt(byte[] data, string keysPair) { if (data == null) { throw new ArgumentNullException(nameof(data)); } if (keysPair == null) { throw new ArgumentNullException(nameof(keysPair)); } CryptoHelper.Separate(out var encryptedKey, out var encryptedData, data, AsymmetricEncryption.KeySize); var commonKey = AsymmetricEncryption.Decrypt(encryptedKey, keysPair); return(SymmetricEncryption.Decrypt(encryptedData, commonKey)); }
public static byte[] Encrypt(byte[] data, string publicKey) { if (data == null) { throw new ArgumentNullException(nameof(data)); } if (publicKey == null) { throw new ArgumentNullException(nameof(publicKey)); } var commonKey = SymmetricEncryption.GenerateKey(); var encryptedKey = AsymmetricEncryption.Encrypt(commonKey, publicKey); var encryptedData = SymmetricEncryption.Encrypt(data, commonKey); CryptoHelper.Concat(encryptedKey, encryptedData, out var result); return(result); }
public static void Encrypt(Stream input, Stream output, string publicKey) { if (input == null) { throw new ArgumentNullException(nameof(input)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } if (publicKey == null) { throw new ArgumentNullException(nameof(publicKey)); } var commonKey = SymmetricEncryption.GenerateKey(); var encryptedKey = AsymmetricEncryption.Encrypt(commonKey, publicKey); output.Write(encryptedKey, 0, encryptedKey.Length); SymmetricEncryption.Encrypt(input, output, commonKey); }
public static void Decrypt(Stream input, Stream output, string keysPair) { if (input == null) { throw new ArgumentNullException(nameof(input)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } if (keysPair == null) { throw new ArgumentNullException(nameof(keysPair)); } var encryptedKey = new byte[AsymmetricEncryption.KeySize]; input.Read(encryptedKey, 0, encryptedKey.Length); var commonKey = AsymmetricEncryption.Decrypt(encryptedKey, keysPair); SymmetricEncryption.Decrypt(input, output, commonKey); }
public static AsymmetricKeys GenerateKeys() => AsymmetricEncryption.GenerateKeys();