Esempio n. 1
0
        public Dictionary <string, string> GetCredential(string key)
        {
            string aliasKey        = String.Format("cachy.{0}", key);
            string credsCipherText = Configuration.GetValue <string>(key, string.Empty);

            if (!String.IsNullOrEmpty(credsCipherText))
            {
                string credsPlainText = AndroidKeyStore.DecodeBase64AndDecrypt(aliasKey, credsCipherText);
                if (!String.IsNullOrEmpty(credsPlainText))
                {
                    JObject credsJSON = JObject.Parse(credsPlainText);
                    Dictionary <string, string> creds = new Dictionary <string, string>
                    {
                        { "UserName", credsJSON["UserName"].Value <string>() },
                        { "Password", credsJSON["Password"].Value <string>() }
                    };
                    return(creds);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
 public Task <string> UnprotectData(string cipherText)
 {
     return(Task <string> .Run(() =>
     {
         string plainText = AndroidKeyStore.DecodeBase64AndDecrypt(
             ANDROIDKEYSTORE_ALIAS,
             cipherText);
         return (plainText);
     }));
 }
Esempio n. 3
0
 public Task <string> ProtectData(string plainText)
 {
     return(Task <string> .Run(() =>
     {
         string cipherText = AndroidKeyStore.EncryptAndBase64Encode(
             ANDROIDKEYSTORE_ALIAS,
             plainText);
         return (cipherText);
     }));
 }
Esempio n. 4
0
        public void StoreCredential(
            string key,
            string username,
            string password,
            bool removeFirst)
        {
            if (removeFirst)
            {
                RemovePassword(key);
            }
            string  aliasKey  = String.Format("cachy.{0}", key);
            JObject credsJSON = new JObject
            {
                { "UserName", new JValue(username) },
                { "Password", new JValue(password) }
            };
            string credsPlainText = credsJSON.ToString(Newtonsoft.Json.Formatting.None);
            string cipherText     = AndroidKeyStore.EncryptAndBase64Encode(aliasKey, credsPlainText);

            Configuration.SetValue <string>(key, cipherText);
        }