public void Test_Decrypt() { var result = AESCryptor.Decrypt("JWm0M2KzKwxe8ylzkfujgQkyEq+kG1ZVirENQqCl8BI=", Key); Output.WriteLine(result); Assert.Equal("测试一下内容先", result); }
public void Test_DecryptIv() { string iv = InitIv(16); Output.WriteLine(iv); var result = AESCryptor.Decrypt("JWm0M2KzKwxe8ylzkfujgV8i5XUnUaHOpY7MaND0Z3g=", Key, Encoding.UTF8, iv, 256, 128, CipherMode.CBC, PaddingMode.PKCS7); Output.WriteLine(result); Assert.Equal("测试一下内容先", result); }
public static byte[] DecryptToBytes(string encryptedData) { if (encryptedData == null) { return(null); } if (string.IsNullOrEmpty(encryptedData)) { return(new byte[0]); } string[] values = encryptedData.Split(Utility.SEPARRAY, StringSplitOptions.None); if (values.Length != 3) { return(null); } int keyIndex; string beEncrypted = values[1]; string nonce = values[2]; if (!int.TryParse(values[0], out keyIndex)) { return(null); } byte[] encrypted = StringTools.FromBase64String(beEncrypted); byte[] binary; AESCryptor.Decrypt(ref keyIndex, ref encrypted, out binary); if (binary == null) { return(null); } byte[] binaryNonce = Encoding.UTF8.GetBytes(nonce); byte[] data; byte[] checkNonceBinary; Utility.SeparateBytes(binary, binaryNonce.Length, out data, out checkNonceBinary); if (!Utility.IsBytesSame(binaryNonce, checkNonceBinary)) { return(null); } return(data); }
public static string Decrypt(string encryptedData) { if (encryptedData == null) { return(null); } if (string.IsNullOrEmpty(encryptedData)) { return(string.Empty); } string[] values = encryptedData.Split(Utility.SEPARRAY, StringSplitOptions.None); if (values.Length != 3) { return(encryptedData); } int keyIndex; string beEncrypted = values[1]; string nonce = values[2]; if (!int.TryParse(values[0], out keyIndex)) { return(encryptedData); } byte[] encrypted = StringTools.FromBase64String(beEncrypted); byte[] binary; AESCryptor.Decrypt(ref keyIndex, ref encrypted, out binary); if (binary == null) { return(encryptedData); } string data = Encoding.UTF8.GetString(binary); string checkNonce = data.Substring(data.Length - NONCE_LENGTH); if (checkNonce != nonce) { return(encryptedData); } return(data.Substring(0, data.Length - NONCE_LENGTH)); }
/// <summary> /// New GTA V GameSave /// </summary> /// <param name="xIn">Gamesave stream</param> /// <param name="key">Encryption key</param> public V(Stream xIn, byte[] key, bool dec) { this.key = key; MemoryStream xMem; byte[] xInBuf = StreamUtils.ReadBytes(xIn, (int)xIn.Length); if (dec) { byte[] deced = AESCryptor.Decrypt(xInBuf, key); xMem = new MemoryStream(deced); } else { xMem = new MemoryStream(xInBuf); } this.Body = new Body(xMem); }
public static byte[] BinaryDecrypt(byte[] encrypted, int you_know_what_is_this_key = 0) { if (encrypted == null) { return(null); } if (encrypted.Length == 0) { return(encrypted); } int keyIndex = you_know_what_is_this_key; byte[] data; AESCryptor.Decrypt(ref keyIndex, ref encrypted, out data); return(data); }