Пример #1
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);
        }
Пример #2
0
        public Dictionary <String, Object> Decrypt(IDictionary <String, Object> map)
        {
            if (map.ContainsKey("token"))
            {
                // 1) extract the encryptedData from map
                IDictionary <String, Object> tokenMap = (IDictionary <String, Object>)map["token"];

                if (tokenMap.ContainsKey("") && tokenMap.ContainsKey(""))
                {
                    //need to read the key
                    String encryptedKey          = (String)tokenMap["encryptedKey"];
                    byte[] encryptedKeyByteArray = CryptUtil.HexDecode(encryptedKey);

                    //need to decryt with RSA
                    byte[] decryptedKeyByteArray = CryptUtil.DecryptRSA(encryptedKeyByteArray, this.privateKey);

                    //need to read the iv
                    String ivString    = (String)tokenMap["iv"];
                    byte[] ivByteArray = CryptUtil.HexDecode(ivString);

                    //need to decrypt the data
                    String encryptedData          = (String)tokenMap["encryptedData"];
                    byte[] encryptedDataByteArray = CryptUtil.HexDecode(encryptedData);

                    byte[] decryptedDataArray  = CryptUtil.DecryptAES(ivByteArray, decryptedKeyByteArray, encryptedDataByteArray);
                    String decryptedDataString = System.Text.Encoding.UTF8.GetString(decryptedDataArray);

                    // remove the field that are not required in the map
                    foreach (String toHide in fieldsToHide)
                    {
                        tokenMap.Remove(toHide);
                    }

                    // add the decrypted data map to the token.
                    Dictionary <String, Object> decryptedDataMap = (Dictionary <String, Object>)RequestMap.AsDictionary(decryptedDataString);
                    foreach (KeyValuePair <String, Object> pair in decryptedDataMap)
                    {
                        tokenMap.Add(pair.Key, pair.Value);
                    }
                }
            }
            return(new Dictionary <String, Object>(map));
        }
Пример #3
0
 public IDictionary <string, object> Decrypt(IDictionary <string, object> map)
 {
     if (map.ContainsKey("token"))
     {
         IDictionary <string, object> dictionary = (IDictionary <string, object>)map["token"];
         if (dictionary.ContainsKey("") && dictionary.ContainsKey(""))
         {
             byte[] encryptionKey = CryptUtil.DecryptRSA(CryptUtil.HexDecode((string)dictionary["encryptedKey"]), this.privateKey);
             byte[] arg_8F_0      = CryptUtil.HexDecode((string)dictionary["iv"]);
             byte[] encryptedData = CryptUtil.HexDecode((string)dictionary["encryptedData"]);
             byte[] bytes         = CryptUtil.DecryptAES(arg_8F_0, encryptionKey, encryptedData);
             string @string       = Encoding.UTF8.GetString(bytes);
             foreach (string current in this.fieldsToHide)
             {
                 dictionary.Remove(current);
             }
             foreach (KeyValuePair <string, object> current2 in ((Dictionary <string, object>)RequestMap.AsDictionary(@string)))
             {
                 dictionary.Add(current2.Key, current2.Value);
             }
         }
     }
     return(map);
 }