public string Decrypt(string cipherText) { if (string.IsNullOrEmpty(cipherText)) { return(cipherText); } byte[] salt = new byte[] { (byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c, (byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99 }; PKCSKeyGenerator crypto = new PKCSKeyGenerator("PASSWORD HERE", salt, 20, 1); ICryptoTransform cryptoTransform = crypto.Decryptor; byte[] cipherBytes = System.Convert.FromBase64String(cipherText); byte[] clearBytes = cryptoTransform.TransformFinalBlock(cipherBytes, 0, cipherBytes.Length); return(Encoding.UTF8.GetString(clearBytes)); }
public void SaveLogin(string where) { byte[] array = new byte[8]; new Random(43287234).NextBytes(array); using (ICryptoTransform cryptoTransform = new PKCSKeyGenerator().Generate("passwordfile", array, 5, 1)) { byte[] bytes = Encoding.UTF8.GetBytes(this.Username + "\n"); byte[] bytes2 = cryptoTransform.TransformFinalBlock(bytes, 0, bytes.Length); File.WriteAllBytes(where, bytes2); } }
private string EncryptPassword(string password) { PKCSKeyGenerator kp = new PKCSKeyGenerator(); ICryptoTransform crypt = kp.Generate("ServiceCenter", GetBytes(timeStamp), 17, // iterations of MD5 hashing 1); // number of 16-byte segments to create. // 1 to mimic Java behaviour. String command = password; byte[] newbytes = crypt.TransformFinalBlock(Encoding.UTF8.GetBytes(command), 0, command.Length); string str = BitConverter.ToString(newbytes).Replace("-", ""); return(str); }
public void SetLastLogin(String username, String password) { byte[] decrypted = BitConverter.GetBytes(IPAddress.NetworkToHostOrder((short)username.Length)) .Concat(System.Text.Encoding.UTF8.GetBytes(username)) .Concat(BitConverter.GetBytes(IPAddress.NetworkToHostOrder((short)password.Length))) .Concat(System.Text.Encoding.UTF8.GetBytes(password)).ToArray(); PKCSKeyGenerator crypto = new PKCSKeyGenerator(LastLoginPassword, LastLoginSalt, 5, 1); ICryptoTransform cryptoTransform = crypto.Encryptor; byte[] encrypted = cryptoTransform.TransformFinalBlock(decrypted, 0, decrypted.Length); if (File.Exists(lastLoginPath)) { File.Delete(lastLoginPath); } using (Stream stream = File.Create(lastLoginPath)) stream.Write(encrypted, 0, encrypted.Length); }
public String[] GetLastLogin() { try { byte[] encryptedLogin = File.ReadAllBytes(lastLoginPath); PKCSKeyGenerator crypto = new PKCSKeyGenerator(LastLoginPassword, LastLoginSalt, 5, 1); ICryptoTransform cryptoTransform = crypto.Decryptor; byte[] decrypted = cryptoTransform.TransformFinalBlock(encryptedLogin, 0, encryptedLogin.Length); short userLength = IPAddress.HostToNetworkOrder(BitConverter.ToInt16(decrypted, 0)); byte[] user = decrypted.Skip(2).Take(userLength).ToArray(); short passLength = IPAddress.HostToNetworkOrder(BitConverter.ToInt16(decrypted, userLength + 2)); byte[] password = decrypted.Skip(4 + userLength).ToArray(); String[] result = new String[2]; result[0] = System.Text.Encoding.UTF8.GetString(user); result[1] = System.Text.Encoding.UTF8.GetString(password); return(result); } catch (Exception e) { MessageBox.Show(e.StackTrace); return(null); } }