Beispiel #1
0
        public void EncryptDecrypt_RSA_Recipients_General()
        {
            string message = "Message to encrypt";
            var    key1    = RSA.Create();
            var    key2    = RSA.Create();
            var    jwe     = new JsonWebEncyption(
                message,
                new JsonHeader
            {
                EncryptionAlgorithm = Encryptions.A128GCM
            },
                "AAD custom value"
                );

            jwe.Recipient(key1, new JsonHeader {
                Algorithm = Algorithms.RSA_OAEP
            });
            jwe.Recipient(key2, new JsonHeader {
                Algorithm = Algorithms.RSA1_5
            });

            jwe.Encrypt();

            var jweEncResult = jwe.Export(ExportType.General);
            var jweDecResult = JsonWebEncyption.Decrypt(jweEncResult, key1);

            Assert.Equal(Encoding.UTF8.GetString(jweDecResult), message);
        }
Beispiel #2
0
        public void EncryptDecrypt_RSA_Recipients_Compact()
        {
            string message = "Message to encrypt";
            var    key1    = RSA.Create();
            var    key2    = RSA.Create();
            var    jwe     = new JsonWebEncyption(
                message,
                new JsonHeader
            {
                EncryptionAlgorithm = Encryptions.A128GCM
            },
                "AAD custom value"
                );

            jwe.Recipient(key1, new JsonHeader {
                Algorithm = Algorithms.RSA_OAEP
            });
            jwe.Recipient(key2, new JsonHeader {
                Algorithm = Algorithms.RSA1_5
            });

            jwe.Encrypt();

            void export() => jwe.Export(ExportType.Compact);

            var ex = Record.Exception(export);

            Assert.NotNull(ex);
        }
Beispiel #3
0
        public void EncryptDecrypt_RSA_Compact()
        {
            string message = "Message to encrypt";
            var    key     = RSA.Create(2048);
            var    jwe     = new JsonWebEncyption(
                message,
                new JsonHeader
            {
                EncryptionAlgorithm = Encryptions.A128GCM,
                Algorithm           = Algorithms.RSA_OAEP,
            }
                );

            jwe.Encrypt(key);

            var jweEncResult = jwe.Export(ExportType.Compact);
            var jweDecResult = JsonWebEncyption.Decrypt(jweEncResult, key);

            Assert.Equal(Encoding.UTF8.GetString(jweDecResult), message);
        }
Beispiel #4
0
        public void EncryptDecrypt_HMAC_General()
        {
            string message = "Message to encrypt";
            var    key     = new HMACSHA256(Utils.Random(128));
            var    jwe     = new JsonWebEncyption(
                message,
                new JsonHeader
            {
                EncryptionAlgorithm = Encryptions.A128CBC_HS256,
                Algorithm           = Algorithms.A128KW,
            },
                "AAD custom value"
                );

            jwe.Encrypt(key);

            var jweEncResult = jwe.Export(ExportType.General);
            var jweDecResult = JsonWebEncyption.Decrypt(jweEncResult, key);

            Assert.Equal(Encoding.UTF8.GetString(jweDecResult), message);
        }