/// <summary> /// Secures the file object with a 3-DES algorithm /// </summary> public FileObject Process(FileObject fo) { FileObject file = new FileObject() { MetadataMD5 = fo.MetadataMD5, IsSecured = false }; try { file.DataContent = _3des.Decrypt(fo.DataContent); } catch (Exception ex) { throw new SmkException( string.Format(ErrorResources.UnsecureTransform_ProcessException, "DataContent", fo.Metadata.FullName), ex); } try { file.MetadataContent = _3des.Decrypt(fo.MetadataContent); } catch (Exception ex) { throw new SmkException( string.Format(ErrorResources.UnsecureTransform_ProcessException, "MetadataContent", fo.Metadata.FullName), ex); } // Deserialize the metadata file.Metadata = file.MetadataContent.XmlToObject <FileMetadata>(); // Be sure the metadata is authentic if (file.MetadataMD5 != MD5.CreateHash(file.Metadata.ToBytes())) { Logger.WriteLog(ErrorCodes.UnsecureTransform_InvalidMetadataSignature, string.Format(ErrorResources.UnsecureTransform_InvalidMetadataSignature, fo.Metadata.FullName), Severity.Warning, VerboseLevel.User); return(null); } // Be sure the original file is authentic if (file.Metadata.OriginalMD5 != MD5.CreateHash(file.DataContent)) { Logger.WriteLog(ErrorCodes.UnsecureTransform_InvalidMetadataSignature, string.Format(ErrorResources.UnsecureTransform_InvalidDataContentSignature, fo.Metadata.FullName), Severity.Warning, VerboseLevel.User); return(null); } return(file); }
public void TripleDESTestDec1() { TripleDES algorithm = new TripleDES(); string plain = algorithm.Decrypt(mainCipherTriple, mainKeyTriple); Assert.IsTrue(plain.Equals(mainPlainTriple, StringComparison.InvariantCultureIgnoreCase)); }
private void buttonDecrypt_Click(object sender, EventArgs e) { string toDecrypt = textInput.Text; string decryptedText = TripleDES.Decrypt(keyHex, toDecrypt); textResult.Text = decryptedText; }
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)); }
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); }
public static string ReturnMsg(string body, string privateKey) { // Текст&ключ&вектор var encryptedItems = body.Split(new string[] { "&" }, StringSplitOptions.RemoveEmptyEntries); if (encryptedItems.Length == 3) { var encryptedKey = Convert.FromBase64String(encryptedItems[1]); var keyHash = RSA.Decrypt(encryptedKey, privateKey); var iv = Convert.FromBase64String(encryptedItems[2]); var txtHash = Convert.FromBase64String(encryptedItems[0]); var decryptedTxt = TripleDES.Decrypt(txtHash, keyHash, iv); return(decryptedTxt); } return(null); }
private void decryptCipherTextButton_Click(object sender, EventArgs e) { string cipherText = this.cipherTextLabel.Text; if (String.IsNullOrWhiteSpace(cipherText)) { MessageBox.Show("Cipher Text is Blank", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { string masterKey = masterKeyLabel.Text; TripleDES des = new TripleDES(); string plainText = des.Decrypt(cipherText, masterKey); this.plainTextTextBox.Text = plainText; } }
/// <summary> /// Determine if the source file object matches with the remote object. /// </summary> public bool IsMetadataMatch(string fullpath, bool isEncrypted, string sourceOriginalMd5) { string localMD5File = BuildMD5FilePath(fullpath); string securedExt = isEncrypted ? Constants.EncryptedExt : string.Empty; string localPath = $"{_path}{fullpath}{securedExt}"; if (!File.Exists(localMD5File)) { return(false); // Missing signature } // For optimization, compares the md5 file firt if (MD5.GetMD5FromFile(localMD5File, MD5Kind.DATA, Logger) != sourceOriginalMd5) { return(false); } // If the file is missing, it must be synchronized if (!File.Exists(localPath)) { return(false); } // Otherwise, calculate a signature from the original file string localOriginalMd5 = null; if (isEncrypted) { TripleDES des = new TripleDES(_transform.Key, _transform.IV); localOriginalMd5 = MD5.CreateHash(des.Decrypt(File.ReadAllBytes(localPath))); } else { localOriginalMd5 = MD5.CreateHash(File.ReadAllBytes(localPath)); } if (localOriginalMd5 != sourceOriginalMd5) { return(false); } return(true); }
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 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 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 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 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 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 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 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 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 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 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 void Dencrypt_Input_NullEmpty() { ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => TripleDES.Decrypt(string.Empty)); Assert.NotNull(ex); }
public static void Main(string[] args) { //!->Has Arguments if (args.Length != 0) { foreach (string arg in args) { FullHashCalc(arg); } } else { //Register Encoding Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); char ch; //Print Title PrintTitle(); //Print Cryptography Table PrintCryptographyTable(); while (true) { ch = Console.ReadKey().KeyChar; if (ch == '1')//Triple-DES { TripleDES tdes = new TripleDES(); Console.Write("\nChoose Encrypt or Decrypt [e/d]: "); while (true) { ch = Console.ReadKey().KeyChar; if (ch == 'e' || ch == 'E') { Console.Write("\nInput PlainText: "); tdes.Text = Console.ReadLine(); string cipherText = tdes.Encrypt(); Console.WriteLine($"Get Random Key: {tdes.Key}"); Console.WriteLine($"Get Random IV: {tdes.IV}"); Console.WriteLine($"The Cipher Text is: {cipherText}"); break; } else if (ch == 'd' || ch == 'D') { Console.Write("\nInput CipherText: "); tdes.Text = Console.ReadLine(); Console.Write("Input Key: "); tdes.Key = Console.ReadLine(); Console.Write("Input IV: "); tdes.IV = Console.ReadLine(); string plainText = tdes.Decrypt(); Console.WriteLine($"The Plain Text is: {plainText}"); break; } } break; } else if (ch == '2')//MD5 { MD5 md5 = new MD5(); Console.Write("\nChoose File or Text [f/t]: "); while (true) { ch = Console.ReadKey().KeyChar; if (ch == 'f' || ch == 'F') { Console.Write("\nInput File Path: "); md5.FilePath = Console.ReadLine(); string hashCode = md5.ComputeHashFromFile(); Console.WriteLine($"The MD5 Code is: {hashCode}"); break; } else if (ch == 't' || ch == 'T') { Console.Write("\nInput Text: "); md5.Text = Console.ReadLine(); string hashCode = md5.ComputeHashFromText(); Console.WriteLine($"The MD5 Code is: {hashCode}"); break; } } break; } else if (ch == '3')//SHA1 { SHA1 sha1 = new SHA1(); Console.Write("\nChoose File or Text [f/t]: "); while (true) { ch = Console.ReadKey().KeyChar; if (ch == 'f' || ch == 'F') { Console.Write("\nInput File Path: "); sha1.FilePath = Console.ReadLine(); string hashCode = sha1.ComputeHashFromFile(); Console.WriteLine($"The SHA1 Code is: {hashCode}"); break; } else if (ch == 't' || ch == 'T') { Console.Write("\nInput Text: "); sha1.Text = Console.ReadLine(); string hashCode = sha1.ComputeHashFromText(); Console.WriteLine($"The SHA1 Code is: {hashCode}"); break; } } break; } else if (ch == '4')//SHA256 { SHA256 sha256 = new SHA256(); Console.Write("\nChoose File or Text [f/t]: "); while (true) { ch = Console.ReadKey().KeyChar; if (ch == 'f' || ch == 'F') { Console.Write("\nInput File Path: "); sha256.FilePath = Console.ReadLine(); string hashCode = sha256.ComputeHashFromFile(); Console.WriteLine($"The SHA256 Code is: {hashCode}"); break; } else if (ch == 't' || ch == 'T') { Console.Write("\nInput Text: "); sha256.Text = Console.ReadLine(); string hashCode = sha256.ComputeHashFromText(); Console.WriteLine($"The SHA256 Code is: {hashCode}"); break; } } break; } else if (ch == '5')//SHA384 { SHA384 sha384 = new SHA384(); Console.Write("\nChoose File or Text [f/t]: "); while (true) { ch = Console.ReadKey().KeyChar; if (ch == 'f' || ch == 'F') { Console.Write("\nInput File Path: "); sha384.FilePath = Console.ReadLine(); string hashCode = sha384.ComputeHashFromFile(); Console.WriteLine($"The SHA384 Code is: {hashCode}"); break; } else if (ch == 't' || ch == 'T') { Console.Write("\nInput Text: "); sha384.Text = Console.ReadLine(); string hashCode = sha384.ComputeHashFromText(); Console.WriteLine($"The SHA384 Code is: {hashCode}"); break; } } break; } else if (ch == '6')//SHA512 { SHA512 sha512 = new SHA512(); Console.Write("\nChoose File or Text [f/t]: "); while (true) { ch = Console.ReadKey().KeyChar; if (ch == 'f' || ch == 'F') { Console.Write("\nInput File Path: "); sha512.FilePath = Console.ReadLine(); string hashCode = sha512.ComputeHashFromFile(); Console.WriteLine($"The SHA512 Code is: {hashCode}"); break; } else if (ch == 't' || ch == 'T') { Console.Write("\nInput Text: "); sha512.Text = Console.ReadLine(); string hashCode = sha512.ComputeHashFromText(); Console.WriteLine($"The SHA512 Code is: {hashCode}"); break; } } break; } else if (ch == '7')//CRC32 { CRC32 crc32 = new CRC32(); Console.Write("\nChoose File or Text [f/t]: "); while (true) { ch = Console.ReadKey().KeyChar; if (ch == 'f' || ch == 'F') { Console.Write("\nInput File Path: "); crc32.FilePath = Console.ReadLine(); string hashCode = crc32.ComputeHashFromFile(); Console.WriteLine($"The CRC32 Code is: {hashCode}"); break; } else if (ch == 't' || ch == 'T') { Console.Write("\nInput Text: "); crc32.Text = Console.ReadLine(); string hashCode = crc32.ComputeHashFromText(); Console.WriteLine($"The CRC32 Code is: {hashCode}"); break; } } break; } else if (ch == '8')//AES { AES aes = new AES(); Console.Write("\nChoose Encrypt or Decrypt [e/d]: "); while (true) { ch = Console.ReadKey().KeyChar; if (ch == 'e' || ch == 'E') { Console.Write("\nInput PlainText: "); aes.Text = Console.ReadLine(); string cipherText = aes.Encrypt(); Console.WriteLine($"Get Random Key: {aes.Key}"); Console.WriteLine($"Get Random IV: {aes.IV}"); Console.WriteLine($"The Cipher Text is: {cipherText}"); break; } else if (ch == 'd' || ch == 'D') { Console.Write("\nInput CipherText: "); aes.Text = Console.ReadLine(); Console.Write("Input Key: "); aes.Key = Console.ReadLine(); Console.Write("Input IV: "); aes.IV = Console.ReadLine(); string plainText = aes.Decrypt(); Console.WriteLine($"The Plain Text is: {plainText}"); break; } } break; } else if (ch == 'f' | ch == 'F')//FULL HASH { FullHashCalc(String.Empty); break; } else if (ch == 'b' | ch == 'B')//BASE64 Code { Console.Write("\nChoose Encode or Decode [e/d]: "); while (true) { ch = Console.ReadKey().KeyChar; if (ch == 'e' || ch == 'E') { Console.Write("\nInput PlainText: "); string plainText = Console.ReadLine(); string cipherText = Base64.Encode(plainText); Console.WriteLine($"The Encoded Text is: {cipherText}"); break; } else if (ch == 'd' || ch == 'D') { Console.Write("\nInput CipherText: "); string cipherText = Console.ReadLine(); string plainText = Base64.Decode(cipherText); Console.WriteLine($"The Plain Text is: {plainText}"); break; } } break; } } } Console.ReadKey(); }
private static void RunTripleDESTesting() { Console.WriteLine("WELCOME TO CRYPTOGRAPHY"); Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine(); Console.WriteLine("Enter 'D' to run the demo. Enter C to use your own key and plain text."); ConsoleKeyInfo cki = Console.ReadKey(true); if (cki.KeyChar == 'd' || cki.KeyChar == 'D') { Console.WriteLine(); Console.WriteLine(); string plainText = GetPlainText(@"PlainText.txt"); string key = GetMasterKey(@"MasterKey.txt"); Console.WriteLine(@"MASTER KEY (Read from Cryptography\Testing\MasterKey.txt): " + key); Console.WriteLine(); Console.WriteLine(@"PLAIN TEXT (Read from Cryptography\Testing\PlainText.txt):"); Console.WriteLine("------------------------------------------------------------------------"); Console.WriteLine(plainText); Console.WriteLine(); Console.WriteLine(); TripleDES tripleDES = new TripleDES(); string cipherText = tripleDES.Encrypt(plainText, key); Console.WriteLine("CIPHER TEXT:"); Console.WriteLine("------------------------------------------------------------------------"); Console.WriteLine(cipherText); Console.WriteLine(); Console.WriteLine(); string plainTextAgain = tripleDES.Decrypt(cipherText, key); Console.WriteLine("CIPHER TEXT DECRYPTED:"); Console.WriteLine("------------------------------------------------------------------------"); Console.WriteLine(plainTextAgain); Console.WriteLine(); Console.WriteLine(); } else if (cki.KeyChar == 'c' || cki.KeyChar == 'C') { Console.WriteLine(); Console.WriteLine("Enter a Master Key to use for Encryption/Decryption"); string key = Console.ReadLine(); Console.WriteLine(); Console.WriteLine("Enter Plain Text to be Encrypted"); string plainText = Console.ReadLine(); TripleDES des = new TripleDES(); string cipherText = des.Encrypt(plainText, key); Console.WriteLine(); Console.WriteLine("CIPHER TEXT:"); Console.WriteLine("------------------------------------------------------------------------"); Console.WriteLine(cipherText); Console.WriteLine(); Console.WriteLine(); string plainTextAgain = des.Decrypt(cipherText, key); Console.WriteLine("CIPHER TEXT DECRYPTED:"); Console.WriteLine("------------------------------------------------------------------------"); Console.WriteLine(plainTextAgain); Console.WriteLine(); Console.WriteLine(); } Console.WriteLine(); Console.WriteLine("Hit Enter to exit"); Console.ReadLine(); }
public void Dencrypt_Input_Invalid() { Exception ex = Assert.Throws <Exception>(() => TripleDES.Decrypt("Invalid")); Assert.NotNull(ex); }
public static string Decrypt(string encryptedString) { return(TripleDES.Decrypt(encryptedString, string.Empty)); }