private static void EncryptAndEmbedIv(Stream dataToEncrypt, byte[] key, Stream destination, byte[] salt) { byte[] iv = CryptoRandom.NextBytesStatic(16); Encrypt(new CryptoRequest { EmbedIV = true, InData = dataToEncrypt, OutData = destination, IV = iv, Key = key, EmbedSalt = salt != null, Salt = salt }); }
private static Task EncryptAndEmbedIvAsync(Stream dataToEncrypt, byte[] key, Stream destination, byte[] salt, ReportAndCancellationToken token = null) { byte[] iv = CryptoRandom.NextBytesStatic(16); return(EncryptAsync(new CryptoRequest { EmbedIV = true, InData = dataToEncrypt, OutData = destination, IV = iv, Key = key, EmbedSalt = salt != null, Salt = salt, Token = token })); }
/// <summary> /// Generates the random salt. /// </summary> /// <returns></returns> public byte[] GenerateRandomSalt() => CryptoRandom.NextBytesStatic(SaltLengthInBytes);