public static void DesExplicitEncryptorDecryptor_WithIV() { using (DES alg = DESFactory.Create()) { alg.Padding = PaddingMode.PKCS7; alg.Mode = CipherMode.CBC; using (ICryptoTransform encryptor = alg.CreateEncryptor(s_randomKey_64.HexToByteArray(), s_randomIv_64.HexToByteArray())) { byte[] plainText1 = s_multiBlockString.HexToByteArray(); byte[] cipher1 = encryptor.Transform(plainText1); byte[] expectedCipher1 = ( "7264319AE3C504148CD4A19B4FDC7D2ACCCB0A08D60CBE2B885DCB2C1A86ED9CA51006E33859B03E00F5B57801EFF745" + "F7A577842461CF39AC143505EC326233E66343A46FEADE9E8456D8AC6A84A1C32E6792857F062400EA9053D17AD3C35D").HexToByteArray(); Assert.Equal <byte>(expectedCipher1, cipher1); } } }
public static void DesExplicitEncryptorDecryptor_NoIV() { using (DES alg = DESFactory.Create()) { alg.Padding = PaddingMode.PKCS7; alg.Mode = CipherMode.ECB; using (ICryptoTransform encryptor = alg.CreateEncryptor(s_randomKey_64.HexToByteArray(), null)) { byte[] plainText1 = s_multiBlockString.HexToByteArray(); byte[] cipher1 = encryptor.Transform(plainText1); byte[] expectedCipher1 = ( "4E42A439ED50C7998CD626B8BE1ECC0A82B985EA772030E87C96BFAE1B97A7666505B8AE96745DE249C1EC3338BBAD41" + "93A9B792205F345E22D45A9A996F21CE24697E5A45F600E8C6E71FC7114A3E96EC4EACC9F652DEBC679D22DE7141F67F").HexToByteArray(); Assert.Equal <byte>(expectedCipher1, cipher1); } } }
public static string TransformToBase64(this ICryptoTransform xfrm, byte[] plain) => xfrm.Transform(plain).ToBase64String();