Пример #1
0
 //It's possible CryptographicException can be thrown if the keys are changed.
 public string Decrypt(string content)
 {
     if (content == null)
     {
         throw new ArgumentNullException(nameof(content));
     }
     using var aesObj = new AesGcmService(_key);
     return(aesObj.Decrypt(content));
 }
Пример #2
0
        //It's possible CryptographicException can be thrown if the keys are changed.
        public XElement Decrypt(XElement encryptedElement)
        {
            if (encryptedElement == null)
            {
                throw new ArgumentNullException(nameof(encryptedElement));
            }

            using var aesObj = new AesGcmService(_key);
            return(XElement.Parse(aesObj.Decrypt(encryptedElement.Element("value")?.Value)));
        }
        public EncryptedXmlInfo Encrypt(XElement plaintextElement)
        {
            if (plaintextElement == null)
            {
                throw new ArgumentNullException(nameof(plaintextElement));
            }

            using var aesObj = new AesGcmService(_key);

            var element = new XElement("encryptedKey",
                                       new XComment(" This key is encrypted with AES-256-GCM. "),
                                       new XElement("value",
                                                    aesObj.Encrypt(plaintextElement.ToString())));

            return(new EncryptedXmlInfo(element, typeof(AesGcmXmlDecryptor)));
        }