예제 #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));
        }
예제 #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]));
        }
예제 #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));
            }
        }
예제 #4
0
 internal static JObject Decrypt(JToken json, Keychain keychain)
 {
     return(JObject.Parse(keychain.Decrypt(Encrypted.Parse(json)).ToUtf8()));
 }
예제 #5
0
 internal static JObject Decrypt(JToken json, AesKey sessionKey)
 {
     return(JObject.Parse(sessionKey.Decrypt(Encrypted.Parse(json)).ToUtf8()));
 }