Esempio n. 1
0
        public void EncryptCompressed()
        {
            string         msg            = "Ths is some content";
            EncryptMessage encryptMessage = new EncryptMessage();

            encryptMessage.SetContent(msg);
            JWK encryptionKey = JWK.GenerateKey("A128GCM");

            // encryptMessage.AddAttribute(HeaderKeys.EncryptionAlgorithm, CBORObject.FromObject(EncryptionAlgorithm), Attributes.PROTECTED);

            Recipient recipient = new Recipient(encryptionKey);

            encryptMessage.AddRecipient(recipient);
            // recipient.ClearUnprotected();
            if (recipient.RecipientType == RecipientType.Direct && encryptionKey.ContainsName("alg"))
            {
                encryptMessage.AddAttribute("enc", encryptionKey.AsString("alg"), Attributes.PROTECTED);
            }
            else
            {
                encryptMessage.AddAttribute("enc", "A128GCM", Attributes.PROTECTED);
            }

            msg = encryptMessage.EncodeCompressed();
        }