/// <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 MD5Encryption() { object oEncryptResult = TSGSecurityManager.Encrypt(strExample, SecurityType.MD5, string.Empty, string.Empty); string strResult = EncryptResult(string.Empty, oEncryptResult); //string strResult = Security.Encrypt(strExample, SecurityType.MD5, string.Empty, string.Empty); Assert.AreEqual("c22ceacbd8a41966a48f43cb7d25ae21", strResult); //"cc8ec790d23c53435ca291e7b969d298" }
/// <summary> /// This is the click event to encrypt image in AES-128 Encryption, AES-256 Encryption and MD5-Hashing. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btnEncryptImage_Click(object sender, RoutedEventArgs e) { try { if (securityType == SecurityType.DEFAULT) { if (lstOptions.Visibility == Visibility.Collapsed) { lstOptions.Visibility = Visibility.Visible; } //await new MessageDialog("Please select encryption option.").ShowAsync(); return; } imgNew.Source = null; string strBase64 = string.Empty; BitmapImage bitmapImage = img.Source as BitmapImage; byte[] bytes = new byte[0]; var sFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///image.jpg", UriKind.RelativeOrAbsolute)); bytes = await GetByteFromFile(sFile); if (securityType == SecurityType.AES128) { object oResult = TSGSecurityManager.Encrypt(bytes, SecurityType.AES128, strAES128Key, strIVector); await DisplayIncryptedResultForData(oResult); btnDecryptImage.Visibility = Visibility.Visible; grdResultImage.Visibility = Visibility.Visible; } else if (securityType == SecurityType.AES256) { object oResult = TSGSecurityManager.Encrypt(bytes, SecurityType.AES256, strAES256Key, strIVector); await DisplayIncryptedResultForData(oResult); btnDecryptImage.Visibility = Visibility.Visible; grdResultImage.Visibility = Visibility.Visible; } else if (securityType == SecurityType.MD5) { object oResult = TSGSecurityManager.Encrypt(bytes, SecurityType.MD5, string.Empty, string.Empty); await DisplayIncryptedResultForData(oResult); btnDecryptImage.Visibility = Visibility.Collapsed; grdResultImage.Visibility = Visibility.Visible; } } catch (Exception ex) { } }
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 encrypt text in AES-128 Encryption, AES-256 Encryption and MD5-Hashing. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btnEncrypt_Click(object sender, RoutedEventArgs e) { if (securityType == SecurityType.DEFAULT) { if (lstOptions.Visibility == Visibility.Collapsed) { lstOptions.Visibility = Visibility.Visible; } //await new MessageDialog("Please select encryption option.").ShowAsync(); return; } txtDecryptResult.Text = string.Empty; if (!string.IsNullOrEmpty(txtMessage.Text.Trim())) { if (securityType == SecurityType.AES128) { object oResult = TSGSecurityManager.Encrypt(txtMessage.Text, SecurityType.AES128, strAES128Key, strIVector); await DisplayIncryptedResultForString(oResult); btnDecrypt.Visibility = Visibility.Visible; } else if (securityType == SecurityType.AES256) { object oResult = TSGSecurityManager.Encrypt(txtMessage.Text, SecurityType.AES256, strAES256Key, strIVector); await DisplayIncryptedResultForString(oResult); btnDecrypt.Visibility = Visibility.Visible; } else if (securityType == SecurityType.MD5) { object oResult = TSGSecurityManager.Encrypt(txtMessage.Text, SecurityType.MD5, string.Empty, string.Empty); await DisplayIncryptedResultForString(oResult); btnDecrypt.Visibility = Visibility.Collapsed; } grdResult.Visibility = Visibility.Visible; } else { await new MessageDialog("Please fill text.").ShowAsync(); } }
/// <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); } } }