public static string Decrypt(string cipherText, string teaKey, Encoding encoding = null) { if (string.IsNullOrEmpty(cipherText)) { return(null); } if (string.IsNullOrEmpty(teaKey)) { return(null); } if (encoding == null) { encoding = Encoding.UTF8; } byte[] x = Convert.FromBase64String(cipherText); uint[] v = StrConvert.StrToLongs(x, 0, 0); // simply convert first 16 chars of password as key x = encoding.GetBytes(teaKey); uint[] k = StrConvert.StrToLongs(x, 0, 16); byte[] decryptText = DecryptBlock(v, k); return(encoding.GetString(decryptText)); }
public static string Encrypt(string plainText, string teaKey, Encoding encoding = null) { if (string.IsNullOrEmpty(plainText)) { return(null); } if (string.IsNullOrEmpty(teaKey)) { return(null); } if (encoding == null) { encoding = Encoding.UTF8; } byte[] x = Encoding.UTF8.GetBytes(plainText); uint[] v = StrConvert.StrToLongs(x, 0, 0); // simply convert first 16 chars of password as key x = encoding.GetBytes(teaKey); uint[] k = StrConvert.StrToLongs(x, 0, 16); byte[] encryptText = EncryptBlock(v, k); return(Convert.ToBase64String(encryptText)); }
public string Decrypt(string cipherText) { if (String.IsNullOrEmpty(cipherText)) { return(null); } byte[] x = Convert.FromBase64String(cipherText); uint[] v = StrConvert.StrToLongs(x, 0, 0); return(Encoding.UTF8.GetString(DecryptBlock(v, teakeyArr))); }
public string Encrypt(string plainText) { if (String.IsNullOrEmpty(plainText)) { return(null); } byte[] x = Encoding.UTF8.GetBytes(plainText); uint[] v = StrConvert.StrToLongs(x, 0, 0); return(Convert.ToBase64String(EncryptBlock(v, teakeyArr))); }
protected override ICryptoValue DecryptInternal(ArraySegment <byte> cipherBytes, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var cipher = GetBytes(cipherBytes); if (cipher.Length == 0) { return(CreateCryptoValue(cipher, cipher, CryptoMode.Decrypt)); } var v = StrConvert.StrToLongs(cipher, 0, 0); var k = StrConvert.StrToLongs(Key.GetKey(), 0, 16); var original = DecryptBlock(v, k); return(CreateCryptoValue(original, cipher, CryptoMode.Decrypt, o => o.TrimTerminatorWhenDecrypting = true)); }
public bool SetTeaKey(string teaKey) { if (String.IsNullOrEmpty(teaKey)) { return(false); } if (teaKey.Length < 16) { return(false); } this.teakey = teaKey; byte[] x = Encoding.UTF8.GetBytes(teaKey); this.teakeyArr = StrConvert.StrToLongs(x, 0, 16); return(true); }
protected override ICryptoValue EncryptInternal(ArraySegment <byte> originalBytes, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var data = GetBytes(originalBytes); if (data.Length == 0) { return(CreateCryptoValue(data, data, CryptoMode.Encrypt)); } var v = StrConvert.StrToLongs(data, 0, 0); var k = StrConvert.StrToLongs(Key.GetKey(), 0, 16); var cipher = EncryptBlock(v, k); return(CreateCryptoValue(data, cipher, CryptoMode.Encrypt)); }
public void SetTeaKey(string teaKey) { this.teakey = teaKey; byte[] x = Encoding.UTF8.GetBytes(teaKey); this.teakeyArr = StrConvert.StrToLongs(x, 0, 16); }