Beispiel #1
0
        public static string Decrypt(this IJObjectCrypto jObjectCrypto, Stream stream, byte[] privateKey)
        {
            var jObject = JObjectTools.GetJObject(stream);

            jObjectCrypto.Decrypt(jObject, privateKey);
            return(JObjectTools.GetJson(jObject));
        }
Beispiel #2
0
        public static string DecryptJson(this IJObjectCrypto jObjectCrypto, string json, byte[] privateKey)
        {
            var jObject = JObjectTools.GetJObject(json);

            jObjectCrypto.Decrypt(jObject, privateKey);
            return(JObjectTools.GetJson(jObject));
        }
Beispiel #3
0
        private JObject GetDecryptJObject(string json, IPrivateKeyProvider keyProvider)
        {
            var jObject   = JObjectTools.GetJObject(json);
            var publicKey = GetPublicKey(jObject);

            keyProvider = keyProvider ?? new DefaultPrivateKeyProvider();
            if (keyProvider.TryGetPrivateKey(publicKey, out string privateKey))
            {
                _jObjectCrypto.Decrypt(jObject, privateKey);
                return(jObject);
            }

            throw new InvalidOperationException($"Could not find private key for: {publicKey}");
        }
Beispiel #4
0
        public static void Decrypt(this IJObjectCrypto jObjectCrypto, JObject jObject, string privateKey)
        {
            var privateKeyBytes = HexConverter.HexToBinary(privateKey);

            jObjectCrypto.Decrypt(jObject, privateKeyBytes);
        }
Beispiel #5
0
        public static string Decrypt(this IJObjectCrypto jObjectCrypto, Stream stream, string privateKey)
        {
            var privateKeyBytes = HexConverter.HexToBinary(privateKey);

            return(jObjectCrypto.Decrypt(stream, privateKeyBytes));
        }