public static void Main(string[] args)
        {
            var domain         = "INSERT YOUR DOMAIN HERE";
            var cryptKeyString = "INSERT YOUR CRYPT KEY HERE";
            var authKeyString  = "INSERT YOUR AUTH KEY HERE";
            var order          = new Order
            {
                Email = "INSERT CONSUMER EMAIL ADDRESS",
                Name  = "INSERT CONSUMER NAME",
                Ref   = "INSERT ORDER REFERENCE NUMBER",
                Skus  = new List <string> {
                    "INSERT SKUS HERE"
                },
                Tags = new List <string> {
                    "INSERT TAGS HERE"
                }
            };
            var jsonEncodedOrder = JsonConvert.SerializeObject(order);
            var cryptKey         = Convert.FromBase64String(cryptKeyString);
            var authKey          = Convert.FromBase64String(authKeyString);

            var cipherText           = AuthenticatedEncryption.Encrypt(jsonEncodedOrder, cryptKey, authKey);
            var urlEncodedCipherText = WebUtility.UrlEncode(cipherText);

            Console.WriteLine($"https://www.trustpilot.com/evaluate-bgl/{domain}?p={urlEncodedCipherText}");
        }
Beispiel #2
0
        public void Encrypt_InvalidMacKey_ThrowException(byte[] macKey)
        {
            byte[] bytes = { 214, 11, 221, 108, 210, 71, 14, 15 };
            byte[] key   = { 251, 9, 67, 117, 237, 158, 138, 150, 255, 97, 103, 128, 183, 65, 76, 161, 7, 79, 244, 225, 146, 180, 51, 123, 118, 167, 45, 10, 184, 181, 202, 190 };

            var encryption = new AuthenticatedEncryption <AesManaged, HMACSHA256>();

            Assert.Throws <ArgumentException>(() => encryption.Encrypt(bytes, key, macKey));
        }
Beispiel #3
0
        public void Encrypt_InvalidKey_ThrowException(byte[] key)
        {
            byte[] bytes  = { 214, 11, 221, 108, 210, 71, 14, 15 };
            byte[] macKey = { 214, 11, 221, 108, 210, 71, 14, 15, 151, 57, 241, 174, 177, 142, 115, 137 };

            var encryption = new AuthenticatedEncryption <AesManaged, HMACSHA256>();

            Assert.Throws <ArgumentException>(() => encryption.Encrypt(bytes, key, macKey));
        }
        public void Encrypt_WhenGivenInput_EncryptsAndDecryptsCorrectly()
        {
            const string Input    = "this is a test input string";
            var          cryptKey = AuthenticatedEncryption.NewKey();
            var          authKey  = AuthenticatedEncryption.NewKey();

            var cipherText = AuthenticatedEncryption.Encrypt(Input, cryptKey, authKey);
            var plainText  = AuthenticatedEncryption.Decrypt(cipherText, cryptKey, authKey);

            plainText.ShouldBe(Input);
        }
Beispiel #5
0
        public override void Save(T target)
        {
            var serializer = new SerializerBuilder().Build();
            var yaml       = serializer.Serialize(target);

            var cryptKey   = _fileSystem.File.ReadAllBytes(_cryptKeyPath);
            var authKey    = _fileSystem.File.ReadAllBytes(_authKeyPath);
            var cipherText = AuthenticatedEncryption.Encrypt(yaml, cryptKey, authKey);
            var cipherPath = _fileSystem.Path.Combine(StorageLocation, target.GetType().Name);

            _fileSystem.File.WriteAllText(cipherPath, cipherText);
        }
Beispiel #6
0
        public void UseCase()
        {
            byte[] bytes  = { 214, 11, 221, 108, 210, 71, 14, 15 };
            byte[] key    = { 251, 9, 67, 117, 237, 158, 138, 150, 255, 97, 103, 128, 183, 65, 76, 161, 7, 79, 244, 225, 146, 180, 51, 123, 118, 167, 45, 10, 184, 181, 202, 190 };
            byte[] macKey = { 214, 11, 221, 108, 210, 71, 14, 15, 151, 57, 241, 174, 177, 142, 115, 137 };

            var encryption = new AuthenticatedEncryption <AesManaged, HMACSHA256>();
            var encrypted  = encryption.Encrypt(bytes, key, macKey);
            var decrypted  = encryption.Decrypt(encrypted, key, macKey);

            Assert.That(bytes, Is.EquivalentTo(decrypted));
        }