예제 #1
0
 public IDictionary <string, object> Encrypt(IDictionary <string, object> map)
 {
     if (map.ContainsKey("cardInfo"))
     {
         string text = JsonConvert.SerializeObject((IDictionary <string, object>)map["cardInfo"]);
         text = CryptUtil.SanitizeJson(text);
         Tuple <byte[], byte[], byte[]> expr_3D = CryptUtil.EncryptAES(Encoding.UTF8.GetBytes(text));
         byte[] item     = expr_3D.Item1;
         byte[] item2    = expr_3D.Item2;
         byte[] arg_57_0 = expr_3D.Item3;
         string value    = CryptUtil.HexEncode(item);
         string value2   = CryptUtil.HexEncode(arg_57_0);
         string value3   = CryptUtil.HexEncode(CryptUtil.EncrytptRSA(item2, this.publicKey));
         string value4   = this.publicKeyFingerPrint;
         Dictionary <string, object> dictionary = new Dictionary <string, object>();
         dictionary.Add("publicKeyFingerprint", value4);
         dictionary.Add("encryptedKey", value3);
         dictionary.Add("oaepHashingAlgorithm", "SHA256");
         dictionary.Add("iv", value);
         dictionary.Add("encryptedData", value2);
         map.Remove("cardInfo");
         map.Add("cardInfo", dictionary);
     }
     return(map);
 }
예제 #2
0
        public void TestHexUnHex()
        {
            String nonHexed = "*****@*****.**";
            String hexed    = CryptUtil.HexEncode(nonHexed);

            byte[] nonHexedBytes = CryptUtil.HexDecode(hexed);
            String nonHexed2     = System.Text.Encoding.UTF8.GetString(nonHexedBytes);

            Assert.AreEqual(nonHexed, nonHexed2);
        }
예제 #3
0
        public Dictionary <String, Object> Encrypt(IDictionary <String, Object> map)
        {
            if (map.ContainsKey("cardInfo"))
            {
                // 1) extract the encryptedData from map
                IDictionary <String, Object> encryptedDataMap = (IDictionary <String, Object>)map["cardInfo"];

                // 2) create json string
                String payload = JsonConvert.SerializeObject(encryptedDataMap);
                // 3) escaping the string
                payload = CryptUtil.SanitizeJson(payload);


                Tuple <byte[], byte[], byte[]> aesResult = CryptUtil.EncryptAES(System.Text.Encoding.UTF8.GetBytes(payload));

                // 4) generate random iv
                byte[] iv = aesResult.Item1;
                // 5) generate AES SecretKey
                byte[] key = aesResult.Item2;
                // 6) encrypt payload
                byte[] encryptedData = aesResult.Item3;

                String hexIv            = CryptUtil.HexEncode(iv);
                String hexEncryptedData = CryptUtil.HexEncode(encryptedData);

                // 7) encrypt secretKey with issuer key


                byte[] encryptedSecretKey = CryptUtil.EncrytptRSA(key, this.publicKey);
                String hexEncryptedKey    = CryptUtil.HexEncode(encryptedSecretKey);

                String fingerprintHexString = publicKeyFingerPrint;


                Dictionary <String, Object> encryptedMap = new Dictionary <String, Object>();
                encryptedMap.Add("publicKeyFingerprint", fingerprintHexString);
                encryptedMap.Add("encryptedKey", hexEncryptedKey);
                encryptedMap.Add("oaepHashingAlgorithm", "SHA256");
                encryptedMap.Add("iv", hexIv);
                encryptedMap.Add("encryptedData", hexEncryptedData);

                map.Remove("cardInfo");
                map.Add("cardInfo", encryptedMap);
            }
            return(new Dictionary <String, Object>(map));
        }