public void TestTripleDESEncryption() { SifEncryption encr = SifEncryption.GetInstance(PasswordAlgorithm.TRIPLEDES, "SECRET_192_BIT_KEY", f192BitKey); AssertEncryption(encr, DEFAULT_ENCRYPTED_STRING); }
public void TestClearTextEncryption() { SifEncryption encr = SifEncryption.GetInstance(PasswordAlgorithm.BASE64, "Base64", null); Assert.AreEqual(string.Empty, encr.KeyName, "Encrytor should have an empty keyName"); AuthenticationInfo info = AssertEncryption(encr, DEFAULT_ENCRYPTED_STRING); Assert.AreEqual(string.Empty, info.PasswordList.ItemAt(0).KeyName, "Password/@KeyName should have an empty value"); }
/// <summary> /// Tests the SifEncryption Class using clear text encryption /// </summary> //[Test, Explicit] //public void TestRSAEncryption() //{ // // This test is not currently run with the full suite of tests because support for RSA encryption is // // not implemented in the ADK // SifEncryption encr = SifEncryption.GetInstance(PasswordAlgorithm.RSA, "SECRET_KEY_RSA", null); // AssertEncryption(encr, DEFAULT_ENCRYPTED_STRING); //} /// <summary> /// Asserts that the password is encrypted and decrypted properly and returns the AuthenticationInfo /// object that was produced in test for further assertions, if necessary /// </summary> /// <param name="encryptor"></param> /// <param name="passwordText"></param> /// <returns></returns> private AuthenticationInfo AssertEncryption(SifEncryption encryptor, string passwordText) { AuthenticationInfo returnValue = null; Authentication auth = CreateAuthentication(); AuthenticationInfo inf = auth.AuthenticationInfo; inf.PasswordList = new PasswordList(); inf.PasswordList.Add(new Password()); // Encrypt the password encryptor.WritePassword(inf.PasswordList.ItemAt(0), passwordText); // Write the object to and and read from xml to assure that the values are being persisted properly Authentication reparsedAuth = (Authentication)AdkObjectParseHelper.WriteParseAndReturn(auth, Adk.SifVersion); returnValue = reparsedAuth.AuthenticationInfo; SifEncryption decryptor = SifEncryption.GetInstance(PasswordAlgorithm.Wrap(returnValue.PasswordList.ItemAt(0).Algorithm), encryptor.KeyName, encryptor.Key); string decryptedValue = decryptor.ReadPassword(returnValue.PasswordList.ItemAt(0)); if (encryptor.IsHash) { // Assert that the decrypted value is the same as the AuthenticationInfoPassword's text value Assert.AreEqual(returnValue.PasswordList.ItemAt(0).TextValue, decryptedValue, "Hashed implementation of ReadPassword() should return the Base64 value"); // Assert that the hash is correct HashAlgorithm hasher = null; if (returnValue.PasswordList.ItemAt(0).Algorithm == PasswordAlgorithm.SHA1.Value) { hasher = new SHA1CryptoServiceProvider(); } else if (returnValue.PasswordList.ItemAt(0).Algorithm == PasswordAlgorithm.MD5.Value) { hasher = new MD5CryptoServiceProvider(); } byte[] preHashed = Encoding.UTF8.GetBytes(passwordText); byte[] hashed = hasher.ComputeHash(preHashed); string textHash = Convert.ToBase64String(hashed); ((IDisposable)hasher).Dispose(); Assert.AreEqual(textHash, decryptedValue, "Hash values do not match"); } else { Assert.AreEqual(passwordText, decryptedValue, "Decypted value differs from original value."); } return(returnValue); }
public void TestRC2Encryption() { SifEncryption encr = SifEncryption.GetInstance(PasswordAlgorithm.RC2, "SECRET_128_BIT_KEY", f128BitKey); AssertEncryption(encr, DEFAULT_ENCRYPTED_STRING); }
public void TestDESEncryption() { SifEncryption encr = SifEncryption.GetInstance(PasswordAlgorithm.DES, "SECRET_64_BIT_KEY", f64BitKey); AssertEncryption(encr, DEFAULT_ENCRYPTED_STRING); }