static void DecryptKey()
        {
            Console.WriteLine("---------------------");
            Console.WriteLine("Decrypting the Key");
            Console.WriteLine("---------------------");
            Console.WriteLine("Please path to the file with encrypted key:");
            var keyfile = Console.ReadLine();

            Console.WriteLine("Please input your password:"******"Cannot read the file!");
                    }

                    var deckey = SymetricProvider.DecryptString(password, key);
                    if (deckey != null)
                    {
                        Console.WriteLine("----------------------");
                        Console.WriteLine("Your Decrypted Key is:");
                        Console.WriteLine();
                        Console.WriteLine(deckey);
                        var pth = Path.GetDirectoryName(keyfile);
                        FileHelpers.WriteTextToFile(Path.Combine(pth, "Deckey-" + FileHelpers.GetDateTimeString() + ".txt"), deckey);
                        Console.WriteLine("----------------------");
                    }
                    else
                    {
                        Console.WriteLine("---------!!!!---------");
                        Console.WriteLine("Cannot Decrypt the Key");
                        Console.WriteLine("----------------------");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("---------!!!!---------");
                    Console.WriteLine("Cannot Decrypt the Key");
                    Console.WriteLine("----------------------");
                }
            }
            else
            {
                Console.WriteLine("Wrong input, please try it again.");
            }
        }
Beispiel #2
0
        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))
            {
                if (PasswordHash?.Length > 0)
                {
                    if (SecurityUtil.VerifyPassword(password, PasswordHash))
                    {
                        return(SymetricProvider.DecryptString(password, _key));
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                if (!IsEncrypted)
                {
                    return(_key);
                }
                else
                {
                    return(null);
                }
            }
        }