using System; using System.Numerics; using System.Text; namespace ArchestrAServices.Contract; public class EncryptionBase { protected BigInteger DH_p = BigInteger.Zero; protected BigInteger DH_g = BigInteger.Zero; public string DH_passphrase { get; set; } public string hashAlgorithm { get; set; } public byte[] NegotiatedKey { get; protected set; } public byte[] Encrypt(byte[] PlainPayload, byte[] EncryptionKey) { if (PlainPayload == null) { throw new ArgumentNullException("PlainPayload"); } if (EncryptionKey == null) { throw new ArgumentNullException("EncryptionKey"); } byte[] bytes = Encoding.UTF8.GetBytes(Constants.SaltValue); byte[] bytes2 = Encoding.UTF8.GetBytes(Constants.InitialVector); return AuthenticationCryptography.Encrypt(PlainPayload, EncryptionKey, bytes, Constants.hashAlgorithm, Constants.PasswordIterations, bytes2, Constants.KeySize); } public byte[] Decrypt(byte[] EncryptedPayload, byte[] EncryptionKey) { if (EncryptedPayload == null) { throw new ArgumentNullException("EncryptedPayload"); } if (EncryptionKey == null) { throw new ArgumentNullException("EncryptionKey"); } byte[] bytes = Encoding.UTF8.GetBytes(Constants.SaltValue); byte[] bytes2 = Encoding.UTF8.GetBytes(Constants.InitialVector); byte[] array = AuthenticationCryptography.Decrypt(EncryptedPayload, EncryptionKey, bytes, Constants.hashAlgorithm, Constants.PasswordIterations, bytes2, Constants.KeySize); int num = array.Length; int num2 = array.Length - 1; while (num2 > 1 && array[num2] == 0) { num--; num2--; } byte[] array2 = new byte[num]; Array.Copy(array, array2, num); return array2; } public byte[] Encrypt(string PlainPayloadString, string EncryptionPassphrase) { if (string.IsNullOrEmpty(PlainPayloadString)) { throw new ArgumentException("PlainPayloadString"); } if (string.IsNullOrEmpty(EncryptionPassphrase)) { throw new ArgumentException("EncryptionPassphrase"); } byte[] bytes = Encoding.UTF8.GetBytes(Constants.SaltValue); byte[] bytes2 = Encoding.UTF8.GetBytes(Constants.InitialVector); byte[] bytes3 = Encoding.UTF8.GetBytes(EncryptionPassphrase); return AuthenticationCryptography.Encrypt(Encoding.UTF8.GetBytes(PlainPayloadString), bytes3, bytes, Constants.hashAlgorithm, Constants.PasswordIterations, bytes2, Constants.KeySize); } public string Decrypt(byte[] EncryptedPayload, string EncryptionPassphrase) { if (EncryptedPayload == null) { throw new ArgumentNullException("EncryptedPayload"); } if (string.IsNullOrEmpty(EncryptionPassphrase)) { throw new ArgumentException("EncryptionPassphrase"); } byte[] bytes = Encoding.UTF8.GetBytes(Constants.SaltValue); byte[] bytes2 = Encoding.UTF8.GetBytes(Constants.InitialVector); byte[] bytes3 = Encoding.UTF8.GetBytes(EncryptionPassphrase); byte[] array = AuthenticationCryptography.Decrypt(EncryptedPayload, bytes3, bytes, Constants.hashAlgorithm, Constants.PasswordIterations, bytes2, Constants.KeySize); int num = array.Length; int num2 = array.Length - 1; while (num2 > 1 && array[num2] == 0) { num--; num2--; } return Encoding.UTF8.GetString(array, 0, num); } }