Exemple #1
0
        /// <summary>
        /// Dencrypt the string with Shared secret
        /// </summary>
        /// <param name="emessage">Message to decrypt</param>
        /// <param name="bobAddress">Receiver Neblio Address</param>
        /// <param name="key">Shared secret key</param>
        /// <returns></returns>
        public static async Task <(bool, string)> DecryptStringWithSharedSecretWithKey(string emessage, string bobAddress, string key)
        {
            if (string.IsNullOrEmpty(emessage))
            {
                return(false, "Message cannot be empty or null.");
            }
            if (string.IsNullOrEmpty(bobAddress))
            {
                return(false, "Partner Address cannot be empty or null.");
            }
            if (string.IsNullOrEmpty(key))
            {
                return(false, "Input secret cannot null.");
            }

            try
            {
                var mesage = SymetricProvider.DecryptString(key, emessage);
                return(true, mesage);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Cannot decrypt message. " + ex.Message);
                return(false, "Cannot decrypt message. " + ex.Message);
            }
        }
        /// <summary>
        /// This is confusing, sorry will be renamed soon
        /// It returns decrypted key if the pass is loaded.
        /// If the pass is not loaded you need to provide pass
        /// If you want encrypted form of the key select returnEncrypted=true
        /// </summary>
        /// <param name="password">fill if the pass is not loaded and you need decrypted key</param>
        /// <param name="returnEncrypted">set true for return enrcypted form of key</param>
        /// <returns></returns>
        public string GetEncryptedKey(string password = "", bool returnEncrypted = false)
        {
            if (returnEncrypted)
            {
                return(_key);
            }

            if (passwordLoaded && string.IsNullOrEmpty(password))
            {
                password = loadedPassword;
            }

            if (!passwordLoaded && string.IsNullOrEmpty(password))
            {
                return(null);
            }

            if (!string.IsNullOrEmpty(password))
            {
                return(SymetricProvider.DecryptString(password, _key));
            }
            else
            {
                if (!IsEncrypted)
                {
                    return(_key);
                }
                else
                {
                    return(null);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Decrypt the string with Shared secret
        /// </summary>
        /// <param name="emessage">Message to decrypt</param>
        /// <param name="bobAddress">Receiver Neblio Address</param>
        /// <param name="secret">Neblio Private Key in form of the BitcoinSecret</param>
        /// <param name="sharedkey">Shared key from some previous call</param>
        /// <returns></returns>
        public static async Task <(bool, string)> DecryptStringWithSharedSecret(string emessage, string bobAddress, BitcoinSecret secret, string sharedkey = "")
        {
            if (string.IsNullOrEmpty(emessage))
            {
                return(false, "Message cannot be empty or null.");
            }
            if (string.IsNullOrEmpty(bobAddress))
            {
                return(false, "Partner Address cannot be empty or null.");
            }
            if (secret == null)
            {
                return(false, "Input secret cannot null.");
            }

            (bool, string)key = (false, "");
            if (string.IsNullOrEmpty(sharedkey))
            {
                key = await GetSharedSecret(bobAddress, secret);

                if (!key.Item1)
                {
                    return(key);
                }
            }
            else
            {
                key = (true, sharedkey);
            }

            try
            {
                var mesage = SymetricProvider.DecryptString(key.Item2, emessage);
                return(true, mesage);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Cannot decrypt message. " + ex.Message);
                return(false, "Cannot decrypt message. " + ex.Message);
            }
        }