Exemplo n.º 1
0
        public byte[] Decrypt(Encrypted encrypted)
        {
            switch (encrypted.Scheme)
            {
            case AesKey.EncryptionScheme:
                return(GetAes(encrypted.KeyId).Decrypt(encrypted));

            case RsaKey.EncryptionScheme:
                return(GetRsa(encrypted.KeyId).Decrypt(encrypted));
            }

            throw ExceptionFactory.MakeInvalidOperation(
                      string.Format("Keychain: Unsupported encryption scheme '{0}'", encrypted.Scheme));
        }
Exemplo n.º 2
0
        public byte[] Decrypt(Encrypted e)
        {
            if (e.KeyId != Id)
            {
                throw ExceptionFactory.MakeInvalidOperation("AES key: mismatching key id");
            }

            if (e.Scheme != EncryptionScheme)
            {
                throw ExceptionFactory.MakeInvalidOperation(
                          string.Format("AES key: invalid encryption scheme '{0}', expected '{1}'",
                                        e.Scheme,
                                        EncryptionScheme));
            }

            return(AesGcm.Decrypt(Key, e.Ciphertext, e.Iv, new byte[0]));
        }
Exemplo n.º 3
0
        public byte[] Decrypt(Encrypted e)
        {
            if (e.KeyId != Id)
            {
                throw ExceptionFactory.MakeInvalidOperation("RSA key: mismatching key id");
            }

            if (e.Scheme != EncryptionScheme)
            {
                throw ExceptionFactory.MakeInvalidOperation(
                          string.Format("RSA key: invalid encryption scheme '{0}', expected '{1}'",
                                        e.Scheme,
                                        EncryptionScheme));
            }

            using (var rsa = new RSACryptoServiceProvider())
            {
                rsa.ImportParameters(Parameters);
                return(rsa.Decrypt(e.Ciphertext, true));
            }
        }
Exemplo n.º 4
0
 internal static JObject Decrypt(JToken json, Keychain keychain)
 {
     return(JObject.Parse(keychain.Decrypt(Encrypted.Parse(json)).ToUtf8()));
 }
Exemplo n.º 5
0
 internal static JObject Decrypt(JToken json, AesKey sessionKey)
 {
     return(JObject.Parse(sessionKey.Decrypt(Encrypted.Parse(json)).ToUtf8()));
 }