public string Decrypt(string toDecrypt, string key) { string @string; try { byte[] array = Convert.FromBase64String(toDecrypt); MD5CryptoServiceProvider mD5CryptoServiceProvider = new MD5CryptoServiceProvider(); byte[] key2 = mD5CryptoServiceProvider.ComputeHash(Encoding.UTF8.GetBytes(key)); ICryptoTransform cryptoTransform = new TripleDESCryptoServiceProvider { Key = key2, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 }.CreateDecryptor(); byte[] bytes = cryptoTransform.TransformFinalBlock(array, 0, array.Length); @string = Encoding.UTF8.GetString(bytes); } catch (Exception ex) { EventLog.WriteEntry("SSOConfigCmdTool - Decrypt", ex.Message); throw ex; } return(@string); }
/// <summary> /// /// </summary> /// <param name="a_strString"></param> /// <param name="a_strKey"></param> /// <returns></returns> public static string Decrypt3DES(string a_strString, string a_strKey) { if (a_strKey.Length < 24) { string str = a_strKey; for (int i = 0; i < (24 / a_strKey.Length); i++) { str = str + a_strKey; } a_strKey = str; } a_strKey = a_strKey.Substring(0, 24); ICryptoTransform transform = new TripleDESCryptoServiceProvider { Key = Encoding.ASCII.GetBytes(a_strKey), Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 }.CreateDecryptor(); string rstr = ""; try { byte[] inputBuffer = Convert.FromBase64String(a_strString); rstr = Encoding.ASCII.GetString(transform.TransformFinalBlock(inputBuffer, 0, inputBuffer.Length)); } catch { } return(rstr); }
/// <summary> /// Decode a string encoded using TripleDES with specified password and IV strings. /// </summary> /// <param name="sourceString">The string to decode</param> /// <param name="password">The password string</param> /// <param name="IV">The IV string</param> /// <returns>The decoded string</returns> public string DecodeString(string sourceString, string password, string IV) { if (string.IsNullOrEmpty(password)) { throw new ArgumentException("Please specify the password", nameof(password)); } if (string.IsNullOrEmpty(IV)) { throw new ArgumentException("Please specify the Initialize Vector", nameof(IV)); } if (!string.IsNullOrEmpty(sourceString)) { byte[] PSS = GeneratePassword(password); byte[] IVb = GeneratePassword(IV); ICryptoTransform ct = new TripleDESCryptoServiceProvider().CreateDecryptor(PSS, IVb); byte[] input = Convert.FromBase64String(sourceString); byte[] output = ct.TransformFinalBlock(input, 0, input.Length); return(Encoding.Unicode.GetString(output)); } else { return(null); } }
/// <summary> /// Decrypts a byte array encrypted with 3DES using the provided key. /// </summary> /// <param name="data">The data to decrypt.</param> /// <param name="key">The encryption as a byte array with length 24.</param> /// <returns>An decrypted byte array</returns> private static byte[] TripleDESDecrypt(byte[] data, byte[] key) { byte[] iv = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }; ICryptoTransform cTranform = new TripleDESCryptoServiceProvider().CreateDecryptor(key, iv); return(cTranform.TransformFinalBlock(data, 0, data.Length)); }
public static string Encrypt3DESWithTrueKey(string sourceStr, string key) { ICryptoTransform transform = new TripleDESCryptoServiceProvider { Key = Encoding.UTF8.GetBytes(key), Mode = CipherMode.ECB }.CreateEncryptor(); byte[] bytes = Encoding.UTF8.GetBytes(sourceStr); return(Convert.ToBase64String(transform.TransformFinalBlock(bytes, 0, bytes.Length))); }
public static string TripleDES_Encrypt(string source, string key, string encoding) { ICryptoTransform transform = new TripleDESCryptoServiceProvider { Key = Encoding.GetEncoding(encoding).GetBytes(key), Mode = CipherMode.ECB }.CreateEncryptor(); byte[] bytes = Encoding.GetEncoding(encoding).GetBytes(source); return(Convert.ToBase64String(transform.TransformFinalBlock(bytes, 0, bytes.Length))); }
public static string DES3Encrypt(string data, string key) { ICryptoTransform transform = new TripleDESCryptoServiceProvider { Key = Encoding.ASCII.GetBytes(key), Mode = CipherMode.CBC, Padding = PaddingMode.PKCS7 }.CreateEncryptor(); byte[] bytes = Encoding.ASCII.GetBytes(data); return(Convert.ToBase64String(transform.TransformFinalBlock(bytes, 0, bytes.Length))); }
/// <summary> /// Encrypts invitation to the ticket /// </summary> /// <returns>Invitation ticket string</returns> public string Encrypt() { var text = WorkroomStartPage.ID.ToString() + separator + (int)MembershipLevel + separator + Email; var data = Encoding.UTF8.GetBytes(text); var transform = new TripleDESCryptoServiceProvider().CreateEncryptor(CryptoKey, iv); var bytes = transform.TransformFinalBlock(data, 0, data.Length); var encodingData = Convert.ToBase64String(bytes); var bytesValue = Encoding.UTF8.GetBytes(encodingData); var base64value = Convert.ToBase64String(bytesValue); var result = HttpUtility.UrlEncode(base64value); return(result); }
/// <summary> /// /// </summary> /// <param name="a_strString"></param> /// <param name="a_strKey"></param> /// <returns></returns> public static string Encrypt3DESJW(string a_strString, string a_strKey) { if (a_strKey.Length < 24) { a_strKey = a_strKey + "000000000000000000000000"; } a_strKey = a_strKey.Substring(0, 24); ICryptoTransform transform = new TripleDESCryptoServiceProvider { Key = Encoding.ASCII.GetBytes(a_strKey), Mode = CipherMode.ECB }.CreateEncryptor(); byte[] bytes = Encoding.ASCII.GetBytes(a_strString); return(Convert.ToBase64String(transform.TransformFinalBlock(bytes, 0, bytes.Length))); }
public static string Decrypt(string toDecrypt, string key) { byte[] array = Convert.FromBase64String(toDecrypt); MD5CryptoServiceProvider mD5CryptoServiceProvider = new MD5CryptoServiceProvider(); byte[] key2 = mD5CryptoServiceProvider.ComputeHash(Encoding.UTF8.GetBytes(key)); ICryptoTransform cryptoTransform = new TripleDESCryptoServiceProvider { Key = key2, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 }.CreateDecryptor(); byte[] bytes = cryptoTransform.TransformFinalBlock(array, 0, array.Length); return(Encoding.UTF8.GetString(bytes)); }
public static string DES3Decrypt(string data, string key) { ICryptoTransform transform = new TripleDESCryptoServiceProvider { Key = Encoding.ASCII.GetBytes(key), Mode = CipherMode.CBC, Padding = PaddingMode.PKCS7 }.CreateDecryptor(); string str = ""; try { byte[] inputBuffer = Convert.FromBase64String(data); str = Encoding.ASCII.GetString(transform.TransformFinalBlock(inputBuffer, 0, inputBuffer.Length)); } catch (Exception) { } return(str); }
public static string Decrypt3DESWithTrueKey(string sourceStr, string key) { ICryptoTransform transform = new TripleDESCryptoServiceProvider { Key = Encoding.UTF8.GetBytes(key), Mode = CipherMode.ECB }.CreateDecryptor(); string str = ""; try { byte[] inputBuffer = Convert.FromBase64String(sourceStr); str = Encoding.UTF8.GetString(transform.TransformFinalBlock(inputBuffer, 0, inputBuffer.Length)); } catch { } return(str); }
public static string Decrypt3DES(string a_strString, string a_strKey) { ICryptoTransform transform = new TripleDESCryptoServiceProvider { Key = Encoding.ASCII.GetBytes(a_strKey), Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 }.CreateDecryptor(); string str = ""; try { byte[] inputBuffer = Convert.FromBase64String(a_strString); str = Encoding.ASCII.GetString(transform.TransformFinalBlock(inputBuffer, 0, inputBuffer.Length)); } catch { } return(str); }
public static string Encrypt3DESSZX(string a_strString, string a_strKey) { if (a_strKey.Length < 0x18) { string str = a_strKey; for (int i = 0; i < (0x18 / a_strKey.Length); i++) { str = str + a_strKey; } a_strKey = str; } a_strKey = a_strKey.Substring(0, 0x18); ICryptoTransform transform = new TripleDESCryptoServiceProvider { Key = Encoding.ASCII.GetBytes(a_strKey), Mode = CipherMode.ECB }.CreateEncryptor(); byte[] bytes = Encoding.ASCII.GetBytes(a_strString); return(Convert.ToBase64String(transform.TransformFinalBlock(bytes, 0, bytes.Length))); }
public static string Decode(string decryptString) { string str = ""; try { string key = GetKey(); byte[] inputBuffer = Convert.FromBase64String(decryptString); byte[] bytes = Encoding.ASCII.GetBytes(key.Substring(0, 0x18)); ICryptoTransform transform = new TripleDESCryptoServiceProvider { Key = bytes, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 }.CreateDecryptor(); str = Encoding.Unicode.GetString(transform.TransformFinalBlock(inputBuffer, 0, inputBuffer.Length)); } catch (Exception) { } return(str); }
private void GeneratePasswordButton_Clicked(object sender, EventArgs e) { if (UniqueIdEntry.Text != null && UniqueIdEntry.Text != "" && MasterPasswordEntry.Text != null && MasterPasswordEntry.Text != "" && MasterPasswordChecksumEntry.Text != null && MasterPasswordChecksumEntry.Text != "") { var Key = Encoding.ASCII.GetBytes(MasterPasswordEntry.Text); ushort KeyChecksum; if (ushort.TryParse(MasterPasswordChecksumEntry.Text, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out KeyChecksum) && Crc16Ccitt(Key) == KeyChecksum) { var TripleDES = new TripleDESCryptoServiceProvider() { Mode = CipherMode.ECB, Padding = PaddingMode.Zeros, Key = PadWithZeros(Key, 16) }.CreateEncryptor(); byte[] Input = Encoding.ASCII.GetBytes(UniqueIdEntry.Text.Length >= 9 ? UniqueIdEntry.Text : UniqueIdEntry.Text + new string(' ', 9 - UniqueIdEntry.Text.Length)); byte[] Output = TripleDES.TransformFinalBlock(Input, 0, Input.Length); int PassLength = 16; var mPassLength = rxPassLength.Match((string)NewPasswordFormatPicker.SelectedItem); if (mPassLength.Success) { PassLength = int.Parse(mPassLength.Groups[1].Value); } if (((string)NewPasswordFormatPicker.SelectedItem).StartsWith("Alphanumeric")) { string Text = Convert.ToBase64String(Output); NewPasswordEntry.Text = (char.ToUpper(Text[0]) + Text.Substring(1, Math.Min(Text.Length - 1, PassLength - 1))).Trim('=') + "#"; } else { NewPasswordEntry.Text = new BigInteger(Output.Concat(new byte[1]).ToArray()).ToString().Substring(0, PassLength); // Add '00' byte to the beginning to make sure the number is unsigned } } else { DisplayAlert("Error", "Invalid checksum for the master password!", "Ok"); } } else { DisplayAlert("Error", "Enter valid unique id and master password!", "Ok"); } }
/// <summary> /// Decrypts invitation from the ticket /// </summary> /// <param name="ticket">Invitation ticket string</param> /// <returns>Invitation object</returns> public static InvitationTicket Decrypt(string ticket) { if (string.IsNullOrEmpty(ticket)) { return(null); } var decodedTicket = HttpUtility.UrlDecode(ticket); var bytes64Value = Convert.FromBase64String(decodedTicket); var decodingData = new string(Encoding.UTF8.GetChars(bytes64Value)); var data = Convert.FromBase64String(decodingData); var transform = new TripleDESCryptoServiceProvider().CreateDecryptor(CryptoKey, iv); var bytes = transform.TransformFinalBlock(data, 0, data.Length); var text = Encoding.UTF8.GetString(bytes).Split(separator); var workroomStartpage = new PageReference(int.Parse(text[0])); var membershipLevel = (MembershipLevels)int.Parse(text[1]); var email = text[2]; return(new InvitationTicket(workroomStartpage, membershipLevel, email)); }
public bool ValidacionAutorizacion(string value) { bool result = false; if (value != null || value != "") { try { DeriveBytes condificacionKey = new Rfc2898DeriveBytes(cadenaSeguridad, Encoding.Unicode.GetBytes(entrada)); SymmetricAlgorithm algoritmoEncriptacion = new TripleDESCryptoServiceProvider(); byte[] claveSimetrica = condificacionKey.GetBytes(algoritmoEncriptacion.KeySize >> 3); byte[] vectorInicializacion = condificacionKey.GetBytes(algoritmoEncriptacion.BlockSize >> 3); ICryptoTransform transform = new TripleDESCryptoServiceProvider().CreateDecryptor(claveSimetrica, vectorInicializacion); byte[] buff = Convert.FromBase64String(value); buff = transform.TransformFinalBlock(buff, 0, buff.Length); string ticket = Encoding.Default.GetString(buff); string[] values = ticket.Split('-'); if (values != null && values.Length == 2) { int userId; long ticks; if (int.TryParse(values[0], out userId) && long.TryParse(values[1], out ticks)) { if (Math.Abs((new DateTime(ticks) - DateTime.Now).Hours) < 8) { result = true; } } } } catch (Exception) { result = false; } } return(result); }
public static string Encrypt(string toEncrypt, string key, bool useHashing) { byte[] bytes = Encoding.UTF8.GetBytes(toEncrypt); byte[] key2; if (useHashing) { MD5CryptoServiceProvider mD5CryptoServiceProvider = new MD5CryptoServiceProvider(); key2 = mD5CryptoServiceProvider.ComputeHash(Encoding.UTF8.GetBytes(key)); } else { key2 = Encoding.UTF8.GetBytes(key); } ICryptoTransform cryptoTransform = new TripleDESCryptoServiceProvider { Key = key2, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 }.CreateEncryptor(); byte[] array = cryptoTransform.TransformFinalBlock(bytes, 0, bytes.Length); return(Convert.ToBase64String(array, 0, array.Length)); }
// Token: 0x06000072 RID: 114 RVA: 0x000049D4 File Offset: 0x00002BD4 public string method_3(string string_0, string string_1, bool bool_0) { byte[] array = Convert.FromBase64String(string_0); byte[] key; if (bool_0) { MD5CryptoServiceProvider md5CryptoServiceProvider = new MD5CryptoServiceProvider(); key = md5CryptoServiceProvider.ComputeHash(Encoding.UTF8.GetBytes(string_1)); } else { key = Encoding.UTF8.GetBytes(string_1); } ICryptoTransform cryptoTransform = new TripleDESCryptoServiceProvider { Key = key, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 }.CreateDecryptor(); byte[] bytes = cryptoTransform.TransformFinalBlock(array, 0, array.Length); return(Encoding.UTF8.GetString(bytes)); }
public static string CrearKeyAutorizacion(string valor) { string result = null; if (valor != null || valor != "") { string key = "{0}-{1}"; key = string.Format(key, valor, DateTime.Now.Ticks); DeriveBytes condificacionKey = new Rfc2898DeriveBytes(cadenaSeguridad, Encoding.Unicode.GetBytes(entrada)); SymmetricAlgorithm algoritmoEncriptacion = new TripleDESCryptoServiceProvider(); byte[] claveSimetrica = condificacionKey.GetBytes(algoritmoEncriptacion.KeySize >> 3); byte[] vectorInicializacion = condificacionKey.GetBytes(algoritmoEncriptacion.BlockSize >> 3); ICryptoTransform transform = new TripleDESCryptoServiceProvider().CreateEncryptor(claveSimetrica, vectorInicializacion); byte[] input = Encoding.Default.GetBytes(key); byte[] buff = new byte[input.Length]; buff = transform.TransformFinalBlock(input, 0, input.Length); result = Convert.ToBase64String(buff); } return(result); }