/// <summary> /// This is the click event to decrypt text in AES-128 Encryption, AES-256 Encryption and MD5-Hashing. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btnDecryptImage_Click(object sender, RoutedEventArgs e) { if (securityType == SecurityType.AES128) { object oResult = TSGSecurityManager.Decrypt(Convert.FromBase64String(txtEncryptImageResult.Text), SecurityType.AES128, strAES128Key, strIVector); await DisplayDecryptedResultForData(oResult); } else if (securityType == SecurityType.AES256) { object oResult = TSGSecurityManager.Decrypt(Convert.FromBase64String(txtEncryptImageResult.Text), SecurityType.AES128, strAES256Key, strIVector); await DisplayDecryptedResultForData(oResult); } else if (securityType == SecurityType.MD5) { string strBase64 = string.Empty; byte[] bytes = new byte[0]; var sFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///image.jpg", UriKind.RelativeOrAbsolute)); bytes = await GetByteFromFile(sFile); strBase64 = Convert.ToBase64String(bytes, 0, bytes.Length); object oResult = TSGSecurityManager.Encrypt(strBase64, SecurityType.MD5, string.Empty, string.Empty); await DisplayDecryptedResultForData(oResult); } }
public void AES128Encryption() { byte[] secureKey = Encoding.UTF8.GetBytes(strAES128Key); byte[] bMessage = Encoding.UTF8.GetBytes(strExample); string strEncryptResult = string.Empty; string strDecryptResult = string.Empty; //strEncryptResult = Security.Encrypt(strExample, SecurityType.AES128, strAES128Key, strIVector); //strDecryptResult = Security.Decrypt(strEncryptResult, SecurityType.AES128, strAES128Key, strIVector); object oEncryptResult = TSGSecurityManager.Encrypt(strExample, SecurityType.AES128, strAES128Key, strIVector); strEncryptResult = EncryptResult(strEncryptResult, oEncryptResult); object oDecryptResult = TSGSecurityManager.Decrypt(strEncryptResult, SecurityType.AES128, strAES128Key, strIVector); strDecryptResult = DecryptResult(strDecryptResult, oDecryptResult); Assert.AreEqual(strDecryptResult, strExample); //"PgvK6FNMxbfzm2HOw6SK+A==" }
public void AES256Encryption() { byte[] secureKey = Encoding.UTF8.GetBytes(strAES256Key); byte[] bMessage = Encoding.UTF8.GetBytes(strExample); string strEncryptResult = string.Empty; string strDecryptResult = string.Empty; object oEncryptResult = TSGSecurityManager.Encrypt(strExample, SecurityType.AES256, strAES256Key, strIVector); strEncryptResult = EncryptResult(strEncryptResult, oEncryptResult); object oDecryptResult = TSGSecurityManager.Decrypt(strEncryptResult, SecurityType.AES256, strAES256Key, strIVector); strDecryptResult = DecryptResult(strDecryptResult, oDecryptResult); //strEncryptResult = Security.Encrypt(strExample, SecurityType.AES256, strAES256Key, strIVector); //strDecryptResult = Security.Decrypt(strEncryptResult, SecurityType.AES256, strAES256Key, strIVector); Assert.AreEqual(strDecryptResult, strExample); //"uyKnSd9iW4Y+N61CTtIsCQ==" }
/// <summary> /// This is the click event to decrypt text in AES-128 Encryption, AES-256 Encryption and MD5-Hashing. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btnDecrypt_Click(object sender, RoutedEventArgs e) { if (!string.IsNullOrEmpty(txtEncryptResult.Text.Trim())) { if (securityType == SecurityType.AES128) { object oResult = TSGSecurityManager.Decrypt(txtEncryptResult.Text, SecurityType.AES128, strAES128Key, strIVector); await DisplayDecryptedResultForString(oResult); } else if (securityType == SecurityType.AES256) { object oResult = TSGSecurityManager.Decrypt(txtEncryptResult.Text, SecurityType.AES256, strAES256Key, strIVector); await DisplayDecryptedResultForString(oResult); } else if (securityType == SecurityType.MD5) { object oResult = TSGSecurityManager.Encrypt(txtMessage.Text, SecurityType.MD5, string.Empty, string.Empty); await DisplayDecryptedResultForString(oResult); } } }