/// <summary> /// Secures the file object with a 3-DES algorithm /// </summary> public FileObject Process(FileObject fo) { try { return(new FileObject() { DataContent = _3des.Encrypt(fo.DataContent), Metadata = new FileMetadata() { Attributes = fo.Metadata.Attributes, LastWriteTime = fo.Metadata.LastWriteTime, Name = fo.Metadata.Name, FullName = fo.Metadata.FullName, OriginalMD5 = fo.Metadata.OriginalMD5 }, MetadataContent = _3des.Encrypt(fo.MetadataContent), MetadataMD5 = fo.MetadataMD5, IsSecured = true }); } catch (Exception ex) { throw new SmkException(string.Format(ErrorResources.SecureTransform_ProcessException, fo.Metadata.FullName), ex); } }
public void TripleDESTestEnc1() { TripleDES algorithm = new TripleDES(); string cipher = algorithm.Encrypt(mainPlainTriple, mainKeyTriple); Assert.IsTrue(cipher.Equals(mainCipherTriple, StringComparison.InvariantCultureIgnoreCase)); }
private CloudApplicationsServer CollectDataForCloudApplicationsServer() { try { //Cluster Settings CloudApplicationsServer CloudApplicationsServerObject = new CloudApplicationsServer(); //12/9/2013 NS added CloudApplicationsServerObject.ID = ID; CloudApplicationsServerObject.Name = CredentialsComboBox.Text; CloudApplicationsServerObject.Category = CategoryTextBox.Text; CloudApplicationsServerObject.Enabled = EnabledCheckBox.Checked; //URLsObject.First_Alert_Threshold = int.Parse(AlertTextBox.Text); CloudApplicationsServerObject.OffHoursScanInterval = int.Parse(OffScanTextBox.Text); CloudApplicationsServerObject.ScanInterval = int.Parse(ScanTextBox.Text); CloudApplicationsServerObject.RetryInterval = int.Parse(RetryTextBox.Text); CloudApplicationsServerObject.ResponseThreshold = int.Parse(RespThrTextBox.Text); CloudApplicationsServerObject.SearchStringNotFound = RequiredTextBox.Text; CloudApplicationsServerObject.SearchStringFound = txtSearch.Text; CloudApplicationsServerObject.URL = IPAddressTextBox.Text; CloudApplicationsServerObject.imageurl = Image1.ImageUrl; CloudApplicationsServerObject.UserName = UserNameTextBox.Text; if (PasswordTextBox.Text != "") { if (PasswordTextBox.Text == " ") { PasswordTextBox.Text = ViewState["PWD"].ToString(); } TripleDES tripleDES = new TripleDES(); byte[] encryptedPass = tripleDES.Encrypt(PasswordTextBox.Text); string encryptedPassAsString = string.Join(", ", encryptedPass.Select(s => s.ToString()).ToArray()); CloudApplicationsServerObject.PW = encryptedPassAsString; } // CloudApplicationsServerObject.PW = PasswordTextBox.Text; Locations LOCobject = new Locations(); ServerTypes STypeobject = new ServerTypes(); STypeobject.ServerType = "Cloud"; ServerTypes ReturnValue = VSWebBL.SecurityBL.ServerTypesBL.Ins.GetDataForServerType(STypeobject); CloudApplicationsServerObject.ServerTypeId = ReturnValue.ID; Locations ReturnLocValue = VSWebBL.SecurityBL.LocationsBL.Ins.GetDataForLocation(LOCobject); CloudApplicationsServerObject.LocationId = ReturnLocValue.ID; CloudApplicationsServerObject.Location = ReturnLocValue.Location; CloudApplicationsServerObject.FailureThreshold = int.Parse(SrvAtrFailBefAlertTextBox.Text); return(CloudApplicationsServerObject); } catch (Exception ex) { //6/27/2014 NS added for VSPLUS-634 Log.Entry.Ins.WriteHistoryEntry(DateTime.Now.ToString() + " Exception - " + ex); throw ex; } finally { } }
/// <summary> /// Генерирует строку зашифрованный текст&защифрованный ключ&вектор&ЭЦП /// </summary> /// <param name="msg"></param> /// <returns></returns> public static MimeMessage GenEncryptedMsg(MimeMessage msg, string body, List <string> attachments, RSABookInfo book) { // encryptedMsg – конечная зашифрованная строка var encryptedMsg = ""; var mailMsg = msg; var tdesKeys = TripleDES.GenKey(); var tdesTxt = Convert.ToBase64String(TripleDES.Encrypt(body, tdesKeys[0], tdesKeys[1])); var encryptedKey = Convert.ToBase64String(RSA.Encrypt(tdesKeys[0], book.EmailPublic)); var iv = Convert.ToBase64String(tdesKeys[1]); var builder = new BodyBuilder(); encryptedMsg += tdesTxt + "&" + encryptedKey + "&" + iv; // Подпись ЭЦП при помощи DSA //encryptedMsg += DSA.CreateSign(encryptedMsg, book.OwnPrivateECP); builder.TextBody = encryptedMsg; builder.HtmlBody = encryptedMsg; foreach (var item in attachments) { builder.Attachments.Add(item); } mailMsg.Body = builder.ToMessageBody(); return(mailMsg); }
public void Encrypt_ShouldWork() { var key = Base64.DecodeCp1252From64("Mk9m98IfEblmPfrpsawt7BmxObt98Jev"); var result = TripleDES.Encrypt(key, "abcdefg"); var base64Result = Base64.EncodeCp1252To64(result); Assert.IsTrue(base64Result == "kQG+7RwPCZo="); }
private void buttonEncrypt_Click(object sender, EventArgs e) { string toEncrypt = textInput.Text; string toEncryptHex = HexConverter.StrToHex(toEncrypt); string encryptedHex = TripleDES.Encrypt(keyHex, toEncryptHex); textResult.Text = encryptedHex; }
public void TripleDESTestFromIssue2() { var unEncryptedString = "This is a test!"; var result = TripleDES.Encrypt(unEncryptedString, string.Empty); Console.WriteLine("Encrypted String " + result); Console.WriteLine("Encrypted String " + TripleDES.Decrypt(result, string.Empty)); }
private NetworkDevices CollectDataForNetworkDevices() { try { //Cluster Settings NetworkDevices NetworkDevicesObject = new NetworkDevices(); NetworkDevicesObject.Name = NameTextBox.Text; NetworkDevicesObject.Enabled = EnabledCheckBox.Checked; NetworkDevicesObject.IncludeOnDashBoard = IncludeOnDashBoardCheckBox.Checked; NetworkDevicesObject.Category = CategoryTextBox.Text; NetworkDevicesObject.ImageURL = Img1.Src; //NetworkDevicesObject.First_Alert_Threshold = int.Parse(AlertTextBox.Text); NetworkDevicesObject.ScanningInterval = int.Parse(ScanIntervalTextBox.Text); NetworkDevicesObject.OffHoursScanInterval = int.Parse(OffScanTextBox.Text); //NetworkDevicesObject.Location = LocComboBox.Text; // LocationTextBox.Text; NetworkDevicesObject.RetryInterval = int.Parse(RetryIntervalTextBox.Text); NetworkDevicesObject.ResponseThreshold = int.Parse(ResponseThrTextBox.Text); NetworkDevicesObject.Address = IPTextBox.Text; NetworkDevicesObject.Description = DescriptionTextBox.Text; Locations LOCobject = new Locations(); LOCobject.Location = LocComboBox.Text; Locations ReturnLocValue = VSWebBL.SecurityBL.LocationsBL.Ins.GetDataForLocation(LOCobject); NetworkDevicesObject.LocationID = ReturnLocValue.ID; NetworkDevicesObject.Location = LocComboBox.Text; NetworkDevicesObject.NetworkType = NetworkTypeCombobox.Text.ToString(); if (PasswordTextBox.Text != "") { if (PasswordTextBox.Text == " ") { PasswordTextBox.Text = ViewState["PWD"].ToString(); } TripleDES tripleDES = new TripleDES(); byte[] encryptedPass = tripleDES.Encrypt(PasswordTextBox.Text); string encryptedPassAsString = string.Join(", ", encryptedPass.Select(s => s.ToString()).ToArray()); NetworkDevicesObject.Password = encryptedPassAsString; } NetworkDevicesObject.Username = UserNameTextBox.Text; if (Mode == "Update") { NetworkDevicesObject.ID = ServerKey; } return(NetworkDevicesObject); } catch (Exception ex) { //6/27/2014 NS added for VSPLUS-634 Log.Entry.Ins.WriteHistoryEntry(DateTime.Now.ToString() + " Exception - " + ex); throw ex; } finally { } }
public void Encrypt_Input_NullEmpty() { ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => TripleDES.Encrypt(string.Empty)); Assert.NotNull(ex); ex = Assert.Throws <ArgumentNullException>(() => TripleDES.Encrypt(null)); Assert.NotNull(ex); }
public string GetSignature(string merchantParameters, string merchantOrder, string merchantKey) { // Se genera una clave específica por operación. Para obtener la clave derivada a utilizar en una operación se debe realizar un cifrado 3DES entre la clave del comercio y el valor del número de pedido de la operación (Ds_Merchant_Order). var key = Base64.DecodeFrom64(merchantKey); var operationKey = TripleDES.Encrypt(key, merchantOrder); // Se calcula el HMAC SHA256 del valor del parámetro Ds_MerchantParameters y la clave obtenida en el paso anterior. var hash = SHA256.HashHMAC(merchantParameters, operationKey); return(hash); }
public void TripleDESTest() { string data = "hello world!"; string password = "******"; string encrypted = TripleDES.Encrypt(data, password); Console.WriteLine(encrypted); string decrypted = TripleDES.Decrypt(encrypted, password); Console.WriteLine(decrypted); encrypted = TripleDES.Encrypt(data, password, 128); Console.WriteLine(encrypted); decrypted = TripleDES.Decrypt(encrypted, password, 128); Console.WriteLine(decrypted); }
public void TripleDESTest() { string data = "hello world!"; string password = "******"; string encrypted = TripleDES.Encrypt(data, password); Console.WriteLine(encrypted); string decrypted = TripleDES.Decrypt(encrypted, password); Console.WriteLine(decrypted); encrypted = TripleDES.Encrypt(data, password, keySize: TripleDESKeySizeFlags.L192); Console.WriteLine(encrypted); decrypted = TripleDES.Decrypt(encrypted, password, keySize: TripleDESKeySizeFlags.L192); Console.WriteLine(decrypted); }
private void encryptPlainTextButton_Click(object sender, EventArgs e) { string plainText = this.plainTextTextBox.Text; if (String.IsNullOrWhiteSpace(plainText)) { MessageBox.Show("Plain Text is Blank", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { string masterKey = masterKeyLabel.Text; TripleDES des = new TripleDES(); string cipherText = des.Encrypt(plainText, masterKey); this.cipherTextLabel.Text = cipherText; } }
public static void TripleDESRoundTrip192BitsPKCS7ECB() { byte[] key = "155425f12109cd89378795a4ca337b3264689dca497ba2fa".HexToByteArray(); using (TripleDES alg = TripleDESFactory.Create()) { alg.Key = key; alg.Padding = PaddingMode.PKCS7; alg.Mode = CipherMode.ECB; byte[] plainText = "5bd3c4e16a723a17ac60dd0efdb158e269cddfd0fa".HexToByteArray(); byte[] cipher = alg.Encrypt(plainText); byte[] expectedCipher = "7b8d982ee0c14821daf1b8cf4e407c2eb328627b696ac36e".HexToByteArray(); Assert.Equal <byte>(expectedCipher, cipher); byte[] decrypted = alg.Decrypt(cipher); byte[] expectedDecrypted = "5bd3c4e16a723a17ac60dd0efdb158e269cddfd0fa".HexToByteArray(); Assert.Equal <byte>(expectedDecrypted, decrypted); } }
public static void TripleDESRoundTrip192BitsNoneECB() { byte[] key = "c5629363d957054eba793093b83739bb78711db221a82379".HexToByteArray(); using (TripleDES alg = TripleDESFactory.Create()) { alg.Key = key; alg.Padding = PaddingMode.None; alg.Mode = CipherMode.ECB; byte[] plainText = "de7d2dddea96b691e979e647dc9d3ca27d7f1ad673ca9570".HexToByteArray(); byte[] cipher = alg.Encrypt(plainText); byte[] expectedCipher = "e56f72478c7479d169d54c0548b744af5b53efb1cdd26037".HexToByteArray(); Assert.Equal <byte>(expectedCipher, cipher); byte[] decrypted = alg.Decrypt(cipher); byte[] expectedDecrypted = "de7d2dddea96b691e979e647dc9d3ca27d7f1ad673ca9570".HexToByteArray(); Assert.Equal <byte>(expectedDecrypted, decrypted); } }
public static void TripleDESRoundTrip192BitsISO10126ECB() { byte[] key = "9da5b265179d65f634dfc95513f25094411e51bb3be877ef".HexToByteArray(); using (TripleDES alg = TripleDESFactory.Create()) { alg.Key = key; alg.Padding = PaddingMode.ISO10126; alg.Mode = CipherMode.ECB; byte[] plainText = "77a8b2efb45addb38d7ef3aa9e6ab5d71957445ab8".HexToByteArray(); byte[] cipher = alg.Encrypt(plainText); // the padding data for ISO10126 is made up of random bytes, so we cannot actually test // the full encrypted text. We need to strip the padding and then compare byte[] decrypted = alg.Decrypt(cipher); Assert.Equal <byte>(plainText, decrypted); } }
public static void TripleDESRoundTrip192BitsZerosECB() { byte[] key = "9da5b265179d65f634dfc95513f25094411e51bb3be877ef".HexToByteArray(); using (TripleDES alg = TripleDESFactory.Create()) { alg.Key = key; alg.Padding = PaddingMode.Zeros; alg.Mode = CipherMode.ECB; byte[] plainText = "77a8b2efb45addb38d7ef3aa9e6ab5d71957445ab8".HexToByteArray(); byte[] cipher = alg.Encrypt(plainText); byte[] expectedCipher = "149ec32f558b27c7e4151e340d8184f18b4e25d2518f69d9".HexToByteArray(); Assert.Equal <byte>(expectedCipher, cipher); byte[] decrypted = alg.Decrypt(cipher); byte[] expectedDecrypted = "77a8b2efb45addb38d7ef3aa9e6ab5d71957445ab8000000".HexToByteArray(); Assert.Equal <byte>(expectedDecrypted, decrypted); } }
public void UpdateId_Test() { int id = 5; var save = false; // Normal ID id = id.UpdateId(TripleDES.Encrypt(1), ref save); Assert.Equal(1, id); Assert.True(save); // Normal ID save = false; id = id.UpdateId(TripleDES.Encrypt(0), ref save); Assert.Equal(0, id); Assert.True(save); // Normal ID save = false; id = id.UpdateId(string.Empty, ref save); Assert.Equal(0, id); Assert.False(save); // Normal ID save = false; id = id.UpdateId(" ", ref save); Assert.Equal(0, id); Assert.False(save); // Normal ID save = false; id = id.UpdateId("Invalid", ref save); Assert.Equal(0, id); Assert.False(save); // Normal ID save = false; id = id.UpdateId(TripleDES.Encrypt(9), ref save); Assert.Equal(9, id); Assert.True(save); }
public static void TripleDESRoundTripNoneECB(int keySize, string expectedCipherHex, string keyHex) { byte[] key = keyHex.HexToByteArray(); using (TripleDES alg = TripleDESFactory.Create()) { alg.Key = key; Assert.Equal(keySize, alg.KeySize); alg.Padding = PaddingMode.None; alg.Mode = CipherMode.ECB; byte[] plainText = "de7d2dddea96b691e979e647dc9d3ca27d7f1ad673ca9570".HexToByteArray(); byte[] cipher = alg.Encrypt(plainText); byte[] expectedCipher = expectedCipherHex.HexToByteArray(); Assert.Equal <byte>(expectedCipher, cipher); byte[] decrypted = alg.Decrypt(cipher); byte[] expectedDecrypted = "de7d2dddea96b691e979e647dc9d3ca27d7f1ad673ca9570".HexToByteArray(); Assert.Equal <byte>(expectedDecrypted, decrypted); } }
public static void TripleDESRoundTripPKCS7ECB(int keySize, string expectedCipherHex, string keyHex) { byte[] key = keyHex.HexToByteArray(); using (TripleDES alg = TripleDESFactory.Create()) { alg.Key = key; Assert.Equal(keySize, alg.KeySize); alg.Padding = PaddingMode.PKCS7; alg.Mode = CipherMode.ECB; byte[] plainText = "5bd3c4e16a723a17ac60dd0efdb158e269cddfd0fa".HexToByteArray(); byte[] cipher = alg.Encrypt(plainText); byte[] expectedCipher = expectedCipherHex.HexToByteArray(); Assert.Equal <byte>(expectedCipher, cipher); byte[] decrypted = alg.Decrypt(cipher); byte[] expectedDecrypted = "5bd3c4e16a723a17ac60dd0efdb158e269cddfd0fa".HexToByteArray(); Assert.Equal <byte>(expectedDecrypted, decrypted); } }
public static void TripleDESRoundTripISO10126ECB(int keySize, string keyHex) { byte[] key = keyHex.HexToByteArray(); using (TripleDES alg = TripleDESFactory.Create()) { alg.Key = key; Assert.Equal(keySize, alg.KeySize); alg.Padding = PaddingMode.ISO10126; alg.Mode = CipherMode.ECB; byte[] plainText = "77a8b2efb45addb38d7ef3aa9e6ab5d71957445ab8".HexToByteArray(); byte[] cipher = alg.Encrypt(plainText); // the padding data for ISO10126 is made up of random bytes, so we cannot actually test // the full encrypted text. We need to strip the padding and then compare byte[] decrypted = alg.Decrypt(cipher); Assert.Equal <byte>(plainText, decrypted); } }
public static void TripleDESRoundTripZerosECB(int keySize, string expectedCipherHex, string keyHex) { byte[] key = keyHex.HexToByteArray(); using (TripleDES alg = TripleDESFactory.Create()) { alg.Key = key; Assert.Equal(keySize, alg.KeySize); alg.Padding = PaddingMode.Zeros; alg.Mode = CipherMode.ECB; byte[] plainText = "77a8b2efb45addb38d7ef3aa9e6ab5d71957445ab8".HexToByteArray(); byte[] cipher = alg.Encrypt(plainText); byte[] expectedCipher = expectedCipherHex.HexToByteArray(); Assert.Equal <byte>(expectedCipher, cipher); byte[] decrypted = alg.Decrypt(cipher); byte[] expectedDecrypted = "77a8b2efb45addb38d7ef3aa9e6ab5d71957445ab8000000".HexToByteArray(); Assert.Equal <byte>(expectedDecrypted, decrypted); } }
public static void TripleDESRoundTrip192BitsZerosCBC() { byte[] key = "5e970c0d2323d53b28fa3de507d6d20f9f0cd97123398b4d".HexToByteArray(); byte[] iv = "95498b5bf570f4c8".HexToByteArray(); using (TripleDES alg = TripleDESFactory.Create()) { alg.Key = key; alg.IV = iv; alg.Padding = PaddingMode.Zeros; alg.Mode = CipherMode.CBC; byte[] plainText = "f9e9a1385bf3bd056d6a06eac662736891bd3e6837".HexToByteArray(); byte[] cipher = alg.Encrypt(plainText); byte[] expectedCipher = "65f3dc211876a9daad238aa7d0c7ed7a3662296faf77dff9".HexToByteArray(); Assert.Equal <byte>(expectedCipher, cipher); byte[] decrypted = alg.Decrypt(cipher); byte[] expectedDecrypted = "f9e9a1385bf3bd056d6a06eac662736891bd3e6837000000".HexToByteArray(); Assert.Equal <byte>(expectedDecrypted, decrypted); } }
public static void TripleDESRoundTrip192BitsPKCS7CBC() { byte[] key = "6b42da08f93e819fbd26fce0785b0eec3d0cb6bfa053c505".HexToByteArray(); byte[] iv = "8fc67ce5e7f28cde".HexToByteArray(); using (TripleDES alg = TripleDESFactory.Create()) { alg.Key = key; alg.IV = iv; alg.Padding = PaddingMode.PKCS7; alg.Mode = CipherMode.CBC; byte[] plainText = "e867f915e275eab27d6951165d26dec6dd0acafcfc".HexToByteArray(); byte[] cipher = alg.Encrypt(plainText); byte[] expectedCipher = "446f57875e107702afde16b57eaf250b87b8110bef29af89".HexToByteArray(); Assert.Equal <byte>(expectedCipher, cipher); byte[] decrypted = alg.Decrypt(cipher); byte[] expectedDecrypted = "e867f915e275eab27d6951165d26dec6dd0acafcfc".HexToByteArray(); Assert.Equal <byte>(expectedDecrypted, decrypted); } }
public static void TripleDESRoundTrip192BitsNoneCBC() { byte[] key = "b43eaf0260813fb47c87ae073a146006d359ad04061eb0e6".HexToByteArray(); byte[] iv = "5fbc5bc21b8597d8".HexToByteArray(); using (TripleDES alg = TripleDESFactory.Create()) { alg.Key = key; alg.IV = iv; alg.Padding = PaddingMode.None; alg.Mode = CipherMode.CBC; byte[] plainText = "79a86903608e133e020e1dc68c9835250c2f17b0ebeed91b".HexToByteArray(); byte[] cipher = alg.Encrypt(plainText); byte[] expectedCipher = "dea36279600f19c602b6ed9bf3ffdac5ebf25c1c470eb61c".HexToByteArray(); Assert.Equal <byte>(expectedCipher, cipher); byte[] decrypted = alg.Decrypt(cipher); byte[] expectedDecrypted = "79a86903608e133e020e1dc68c9835250c2f17b0ebeed91b".HexToByteArray(); Assert.Equal <byte>(expectedDecrypted, decrypted); } }
public static void TripleDESRoundTripNoneCBC(int keySize, string expectedCipherHex, string keyHex) { byte[] key = keyHex.HexToByteArray(); byte[] iv = "5fbc5bc21b8597d8".HexToByteArray(); using (TripleDES alg = TripleDESFactory.Create()) { alg.Key = key; Assert.Equal(keySize, alg.KeySize); alg.IV = iv; alg.Padding = PaddingMode.None; alg.Mode = CipherMode.CBC; byte[] plainText = "79a86903608e133e020e1dc68c9835250c2f17b0ebeed91b".HexToByteArray(); byte[] cipher = alg.Encrypt(plainText); byte[] expectedCipher = expectedCipherHex.HexToByteArray(); Assert.Equal <byte>(expectedCipher, cipher); byte[] decrypted = alg.Decrypt(cipher); byte[] expectedDecrypted = "79a86903608e133e020e1dc68c9835250c2f17b0ebeed91b".HexToByteArray(); Assert.Equal <byte>(expectedDecrypted, decrypted); } }
public static void TripleDESRoundTripPKCS7CBC(int keySize, string expectedCipherHex, string keyHex) { byte[] key = keyHex.HexToByteArray(); byte[] iv = "8fc67ce5e7f28cde".HexToByteArray(); using (TripleDES alg = TripleDESFactory.Create()) { alg.Key = key; Assert.Equal(keySize, alg.KeySize); alg.IV = iv; alg.Padding = PaddingMode.PKCS7; alg.Mode = CipherMode.CBC; byte[] plainText = "e867f915e275eab27d6951165d26dec6dd0acafcfc".HexToByteArray(); byte[] cipher = alg.Encrypt(plainText); byte[] expectedCipher = expectedCipherHex.HexToByteArray(); Assert.Equal <byte>(expectedCipher, cipher); byte[] decrypted = alg.Decrypt(cipher); byte[] expectedDecrypted = "e867f915e275eab27d6951165d26dec6dd0acafcfc".HexToByteArray(); Assert.Equal <byte>(expectedDecrypted, decrypted); } }
public static void TripleDESRoundTripZerosCBC(int keySize, string expectedCipherHex, string keyHex) { byte[] key = keyHex.HexToByteArray(); byte[] iv = "95498b5bf570f4c8".HexToByteArray(); using (TripleDES alg = TripleDESFactory.Create()) { alg.Key = key; Assert.Equal(keySize, alg.KeySize); alg.IV = iv; alg.Padding = PaddingMode.Zeros; alg.Mode = CipherMode.CBC; byte[] plainText = "f9e9a1385bf3bd056d6a06eac662736891bd3e6837".HexToByteArray(); byte[] cipher = alg.Encrypt(plainText); byte[] expectedCipher = expectedCipherHex.HexToByteArray(); Assert.Equal <byte>(expectedCipher, cipher); byte[] decrypted = alg.Decrypt(cipher); byte[] expectedDecrypted = "f9e9a1385bf3bd056d6a06eac662736891bd3e6837000000".HexToByteArray(); Assert.Equal <byte>(expectedDecrypted, decrypted); } }
public static void TripleDES_FailureToRoundTrip192Bits_DifferentPadding_ANSIX923_ZerosECB() { byte[] key = "9da5b265179d65f634dfc95513f25094411e51bb3be877ef".HexToByteArray(); using (TripleDES alg = TripleDESFactory.Create()) { alg.Key = key; alg.Padding = PaddingMode.ANSIX923; alg.Mode = CipherMode.ECB; byte[] plainText = "77a8b2efb45addb38d7ef3aa9e6ab5d71957445ab8".HexToByteArray(); byte[] cipher = alg.Encrypt(plainText); byte[] expectedCipher = "149ec32f558b27c7e4151e340d8184f1c90f0a499e20fda9".HexToByteArray(); Assert.Equal <byte>(expectedCipher, cipher); alg.Padding = PaddingMode.Zeros; byte[] decrypted = alg.Decrypt(cipher); byte[] expectedDecrypted = "77a8b2efb45addb38d7ef3aa9e6ab5d71957445ab8".HexToByteArray(); // They should not decrypt to the same value Assert.NotEqual <byte>(plainText, decrypted); } }
//public static bool LoadConfiguration(List<T> configurationCollection) //{ // return false; //} public static string Encrpyt(string unEncryptedString) { var result = TripleDES.Encrypt(unEncryptedString, string.Empty); return(result); }