コード例 #1
0
        public void Decrypt_works_as_expected()
        {
            // arrange
            var privateKey = "5f349a6bf95d692830a8930aa657b5d553073e589564925f153c018b5c27c8b6";

            var ejson = @"{
  ""_public_key"": ""749d901c694890ee91b7d2c366c2d59dc7b6b8a386d0a5be73431e622b91d117"",
  ""passwords"": {
    ""database_password"": ""EJ[1:EtX9E9y07M9ppTIeiLgdMysdWgmWNPvdNRBMtHKuDQo=:ZQqM6wGxUUiRy2kXYVinPKEFIyMRubvL:OR5Owty2fMOPTownI2/xngsWISvD]""
  }
}";

            var expectedDecrypted = @"{
  ""_public_key"": ""749d901c694890ee91b7d2c366c2d59dc7b6b8a386d0a5be73431e622b91d117"",
  ""passwords"": {
    ""database_password"": ""hello""
  }
}";

            var crypto = new JObjectCrypto();

            // act
            var actualDecrypted = crypto.DecryptJson(ejson, privateKey);

            // assert
            Assert.Equal(JObjectTools.NormalizeJson(expectedDecrypted), JObjectTools.NormalizeJson(actualDecrypted));
        }
コード例 #2
0
ファイル: EjsonCrypto.cs プロジェクト: jakegough/jaytwo.ejson
        private JObject GetEncryptedJObject(string json)
        {
            var jObject   = JObjectTools.GetJObject(json);
            var publicKey = GetPublicKey(jObject);

            _jObjectCrypto.Encrypt(jObject, publicKey);

            return(jObject);
        }
コード例 #3
0
ファイル: EjsonCrypto.cs プロジェクト: jakegough/jaytwo.ejson
        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}");
        }
コード例 #4
0
        public void Encrypt_and_Decrypt_works_as_expected()
        {
            // arrange
            var publicKey  = "749d901c694890ee91b7d2c366c2d59dc7b6b8a386d0a5be73431e622b91d117";
            var privateKey = "5f349a6bf95d692830a8930aa657b5d553073e589564925f153c018b5c27c8b6";

            var json = @"{
  ""passwords"": {
    ""database_password"": ""hello""
  }
}";

            var crypto = new JObjectCrypto();

            // act
            var encrypted = crypto.EncryptJson(json, publicKey);
            var decrypted = crypto.DecryptJson(encrypted, privateKey);

            // assert
            Assert.Equal(JObjectTools.NormalizeJson(decrypted), JObjectTools.NormalizeJson(json));
        }
コード例 #5
0
ファイル: EjsonCrypto.cs プロジェクト: jakegough/jaytwo.ejson
        public string GetEncryptedJson(string json)
        {
            var jObject = GetEncryptedJObject(json);

            return(JObjectTools.GetJson(jObject));
        }
コード例 #6
0
ファイル: EjsonCrypto.cs プロジェクト: jakegough/jaytwo.ejson
        public string GetDecryptedJson(string json, IPrivateKeyProvider keyProvider = null)
        {
            var jObject = GetDecryptJObject(json, keyProvider);

            return(JObjectTools.GetJson(jObject));
        }