public void GenerateKey_KeySize192() { var key = Symmetric.GenerateKey("GenerateKey_KeySize192", "salt", keySize: KeySize.Bits192); var keyB64 = Convert.ToBase64String(key); Assert.AreEqual("eJmnbYPLuu1cUx4WRfUgH/PXzhQI7NLp", keyB64); }
public void GenerateKey_KeySize128() { var key = Symmetric.GenerateKey("GenerateKey_KeySize128", "salt", keySize: KeySize.Bits128); var keyB64 = Convert.ToBase64String(key); Assert.AreEqual("MPkpMHyGEYhK9ymWaVSMfg==", keyB64); }
public void GenerateKey_MD5() { var key = Symmetric.GenerateKey("GenerateKey_MD5", "salt", TNT.Cryptography.Enumerations.HashAlgorithm.MD5); var keyB64 = Convert.ToBase64String(key); Assert.AreEqual("oaVJMDQueZox8TP9E9Wrz0Fwxquezw3Sw7JjmdRIBHs=", keyB64); }
public void GenerateKey_Defaults() { var key = Symmetric.GenerateKey("GenerateKey_Defaults", "salt"); var keyB64 = Convert.ToBase64String(key); Assert.AreEqual("XMIqI9XOfHYsg0+y7vtLvGReLaWs1z6QwM+9faMjSXw=", keyB64); }
public void Constructor_WithBase64String() { var key = Convert.ToBase64String(Symmetric.GenerateKey("Constructor_WithByteArray", "salt")); var sut = new Symmetric(key); Assert.AreEqual(key, Convert.ToBase64String(sut.Key)); }
public void Constructor_WithByteArray() { var key = Symmetric.GenerateKey("Constructor_WithByteArray", "salt"); var sut = new Symmetric(key); Assert.AreEqual(key, sut.Key); }
public void BasicCanDecryptTest() { const string PLAINTEXT = "SmartEncryption Sym Test"; var key = Symmetric.GenerateKey(); var cipher = Symmetric.Encrypt(Encoding.UTF8.GetBytes(PLAINTEXT), key); var plain = Symmetric.Decrypt(cipher, key); Assert.AreEqual(PLAINTEXT, Encoding.UTF8.GetString(plain)); }
/// <summary> /// Asynchronously initializes the symmetric key for encryption. /// </summary> /// <returns> /// A <see cref="Task"/> object representing the process of asynchronous initialization. /// </returns> protected virtual async Task InitializeSymmetricKeyAsync() { if (IsSymmetricKeyInitialized) { return; } // get or create and put the file from/to its location if (KeyStorage.KeyLocationExists(KeyLocation)) { DecryptSymmetricKey(await KeyStorage.GetKeyAsync(KeyLocation)); } else { Symmetric.GenerateKey(); await KeyStorage.PutKeyAsync(EncryptSymmetricKey(), KeyLocation); } IsSymmetricKeyInitialized = true; }
/// <summary> /// Initializes the symmetric key for encryption. /// </summary> protected virtual void InitializeSymmetricKey() { if (IsSymmetricKeyInitialized) { return; } // get or create and put the file from/to its physical location if (KeyStorage.KeyLocationExists(KeyLocation)) { DecryptSymmetricKey(KeyStorage.GetKey(KeyLocation)); } else { Symmetric.GenerateKey(); KeyStorage.PutKey(EncryptSymmetricKey(), KeyLocation); } IsSymmetricKeyInitialized = true; }
/// <summary> /// Initializes the symmetric key by either reading it from the storage with the specified key location name or by /// generating a new key and saving it in it. /// </summary> /// <remarks>The method is called by the GoF template-methods.</remarks> protected override void InitializeSymmetricKey() { Symmetric.GenerateKey(); Symmetric.GenerateIV(); IsSymmetricKeyInitialized = true; }