private void buttonConfirm_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxConfirmation.Text) ||
                string.IsNullOrEmpty(textBoxEncKey.Text) ||
                string.IsNullOrEmpty(textBoxPassword.Text) ||
                string.IsNullOrEmpty(textBoxAddress.Text))
            {
                MessageBox.Show(this, "You need to [Generate Key] first.", "knoledge-keychain", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            using (new HourGlass())
            {
                try
                {
                    BitcoinConfirmationCode  confirmationCode = new BitcoinConfirmationCode(textBoxConfirmation.Text, Network.TestNet);
                    BitcoinEncryptedSecretEC encKey           = new BitcoinEncryptedSecretEC(textBoxEncKey.Text, Network.TestNet);
                    BitcoinSecret            secret           = encKey.GetSecret(textBoxPassword.Text);
                    BitcoinAddress           address          = new BitcoinAddress(textBoxAddress.Text);

                    if (confirmationCode.Check(textBoxPassword.Text, address))
                    {
                        if (secret.GetAddress() == address)
                        {
                            MessageBox.Show(this, "Confirmation that this Address depends on the Passphrase", "knoledge-keychain", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, "knoledge-keychain", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
示例#2
0
        public void KeyParseWorksOnBothTypeOfEncryptedKey()
        {
            BitcoinEncryptedSecretNoEC encryptedkey = new Key().GetEncryptedBitcoinSecret("abc", Network.Main);

            Key.Parse(encryptedkey.ToString(), "abc", Network.Main);

            var code = new BitcoinPassphraseCode("abc", Network.Main, null);
            BitcoinEncryptedSecretEC encryptedkey2 = code.GenerateEncryptedSecret().EncryptedKey;

            Key.Parse(encryptedkey2.ToString(), "abc", Network.Main);
        }
示例#3
0
        public void EncryptedSecretECmultiplyLotSequence()
        {
            var tests = new[]
            {
                new {
                    Passphrase       = "ΜΟΛΩΝ ΛΑΒΕ",
                    PassphraseCode   = "passphrased3z9rQJHSyBkNBwTRPkUGNVEVrUAcfAXDyRU1V28ie6hNFbqDwbFBvsTK7yWVK",
                    Encrypted        = "6PgGWtx25kUg8QWvwuJAgorN6k9FbE25rv5dMRwu5SKMnfpfVe5mar2ngH",
                    Address          = "1Lurmih3KruL4xDB5FmHof38yawNtP9oGf",
                    Unencrypted      = "5KMKKuUmAkiNbA3DazMQiLfDq47qs8MAEThm4yL8R2PhV1ov33D",
                    ConfirmationCode = "cfrm38V8G4qq2ywYEFfWLD5Cc6msj9UwsG2Mj4Z6QdGJAFQpdatZLavkgRd1i4iBMdRngDqDs51",
                    LotSequence      = new LotSequence(806938, 1),
                    Compressed       = false
                }
                , new {
                    Passphrase       = "MOLON LABE",
                    PassphraseCode   = "passphraseaB8feaLQDENqCgr4gKZpmf4VoaT6qdjJNJiv7fsKvjqavcJxvuR1hy25aTu5sX",
                    Encrypted        = "6PgNBNNzDkKdhkT6uJntUXwwzQV8Rr2tZcbkDcuC9DZRsS6AtHts4Ypo1j",
                    Address          = "1Jscj8ALrYu2y9TD8NrpvDBugPedmbj4Yh",
                    Unencrypted      = "5JLdxTtcTHcfYcmJsNVy1v2PMDx432JPoYcBTVVRHpPaxUrdtf8",
                    ConfirmationCode = "cfrm38V8aXBn7JWA1ESmFMUn6erxeBGZGAxJPY4e36S9QWkzZKtaVqLNMgnifETYw7BPwWC9aPD",
                    LotSequence      = new LotSequence(263183, 1),
                    Compressed       = false
                }
            };

            foreach (var test in tests)
            {
                //Can generate unencrypted key with password and encrypted key
                var encryptedKey = new BitcoinEncryptedSecretEC(test.Encrypted, Network.Main);
                AssertSequenceEquals(test.LotSequence, encryptedKey.LotSequence);
                Key actualKey = encryptedKey.GetKey(test.Passphrase);
                Assert.Equal(test.Unencrypted, actualKey.GetBitcoinSecret(Network.Main).ToString());
                Assert.Equal(test.Address, actualKey.PubKey.GetAddress(Network.Main).ToString());
                Assert.Equal(test.Compressed, actualKey.IsCompressed);


                //Can generate same BitcoinPassphraseCode with by using same ownerentropy
                var passCode = new BitcoinPassphraseCode(test.PassphraseCode, Network.Main);
                AssertSequenceEquals(test.LotSequence, passCode.LotSequence);
                var actualPassCode = new BitcoinPassphraseCode(test.Passphrase, Network.Main, test.LotSequence, passCode.OwnerEntropy);
                Assert.Equal(passCode.ToString(), actualPassCode.ToString());

                //Can verify confirmation
                var confirmation = new BitcoinConfirmationCode(test.ConfirmationCode, Network.Main);
                AssertSequenceEquals(confirmation.LotSequence, test.LotSequence);
                Assert.True(confirmation.Check(test.Passphrase, new BitcoinPubKeyAddress(test.Address, Network.Main)));

                //Can generate encrypted key from passcode
                BitcoinEncryptedSecretEC generatedEncryptedKey = passCode.GenerateEncryptedSecret(test.Compressed).EncryptedKey;
                AssertEx.CollectionEquals(passCode.OwnerEntropy, generatedEncryptedKey.OwnerEntropy);
                Assert.Equal(test.Compressed, generatedEncryptedKey.IsCompressed);
            }
        }
示例#4
0
        public void EncryptedSecretECmultiplyNoLot()
        {
            var tests = new[]
            {
                new {
                    Passphrase     = "TestingOneTwoThree",
                    PassphraseCode = "passphrasepxFy57B9v8HtUsszJYKReoNDV6VHjUSGt8EVJmux9n1J3Ltf1gRxyDGXqnf9qm",
                    Encrypted      = "6PfQu77ygVyJLZjfvMLyhLMQbYnu5uguoJJ4kMCLqWwPEdfpwANVS76gTX",
                    Address        = "1PE6TQi6HTVNz5DLwB1LcpMBALubfuN2z2",
                    Unencrypted    = "5K4caxezwjGCGfnoPTZ8tMcJBLB7Jvyjv4xxeacadhq8nLisLR2",
                    Compressed     = false
                },
                new {
                    Passphrase     = "Satoshi",
                    PassphraseCode = "passphraseoRDGAXTWzbp72eVbtUDdn1rwpgPUGjNZEc6CGBo8i5EC1FPW8wcnLdq4ThKzAS",
                    Encrypted      = "6PfLGnQs6VZnrNpmVKfjotbnQuaJK4KZoPFrAjx1JMJUa1Ft8gnf5WxfKd",
                    Address        = "1CqzrtZC6mXSAhoxtFwVjz8LtwLJjDYU3V",
                    Unencrypted    = "5KJ51SgxWaAYR13zd9ReMhJpwrcX47xTJh2D3fGPG9CM8vkv5sH",
                    Compressed     = false
                }
            };

            foreach (var test in tests)
            {
                //Can generate unencrypted key with password and encrypted key
                var encryptedKey = new BitcoinEncryptedSecretEC(test.Encrypted, Network.Main);
                Assert.Null(encryptedKey.LotSequence);
                Key actualKey = encryptedKey.GetKey(test.Passphrase);
                Assert.Equal(test.Unencrypted, actualKey.GetBitcoinSecret(Network.Main).ToString());
                Assert.Equal(test.Address, actualKey.PubKey.GetAddress(Network.Main).ToString());
                Assert.Equal(test.Compressed, actualKey.IsCompressed);


                //Can generate same BitcoinPassphraseCode with by using same ownerentropy
                var passCode = new BitcoinPassphraseCode(test.PassphraseCode, Network.Main);
                Assert.Null(passCode.LotSequence);
                var actualPassCode = new BitcoinPassphraseCode(test.Passphrase, Network.Main, null, passCode.OwnerEntropy);
                Assert.Equal(passCode.ToString(), actualPassCode.ToString());

                //Can generate encrypted key from passcode
                BitcoinEncryptedSecretEC generatedEncryptedKey = passCode.GenerateEncryptedSecret(test.Compressed).EncryptedKey;
                AssertEx.CollectionEquals(passCode.OwnerEntropy, generatedEncryptedKey.OwnerEntropy);
                Assert.Equal(test.Compressed, generatedEncryptedKey.IsCompressed);
            }
        }
示例#5
0
		public void EncryptedSecretECmultiplyNoLot()
		{
			var tests = new[]
			{
				new {
				Passphrase= "TestingOneTwoThree",
				PassphraseCode= "passphrasepxFy57B9v8HtUsszJYKReoNDV6VHjUSGt8EVJmux9n1J3Ltf1gRxyDGXqnf9qm",
				Encrypted = "6PfQu77ygVyJLZjfvMLyhLMQbYnu5uguoJJ4kMCLqWwPEdfpwANVS76gTX",
				Address = "1PE6TQi6HTVNz5DLwB1LcpMBALubfuN2z2",
				Unencrypted = "5K4caxezwjGCGfnoPTZ8tMcJBLB7Jvyjv4xxeacadhq8nLisLR2",
				Compressed = false
				},
				new {
				Passphrase= "Satoshi",
				PassphraseCode= "passphraseoRDGAXTWzbp72eVbtUDdn1rwpgPUGjNZEc6CGBo8i5EC1FPW8wcnLdq4ThKzAS",
				Encrypted = "6PfLGnQs6VZnrNpmVKfjotbnQuaJK4KZoPFrAjx1JMJUa1Ft8gnf5WxfKd",
				Address = "1CqzrtZC6mXSAhoxtFwVjz8LtwLJjDYU3V",
				Unencrypted = "5KJ51SgxWaAYR13zd9ReMhJpwrcX47xTJh2D3fGPG9CM8vkv5sH",
				Compressed = false
				}
			};
			foreach(var test in tests)
			{
				//Can generate unencrypted key with password and encrypted key
				var encryptedKey = new BitcoinEncryptedSecretEC(test.Encrypted, Network.Main);
				Assert.Null(encryptedKey.LotSequence);
				var actualKey = encryptedKey.GetKey(test.Passphrase);
				Assert.Equal(test.Unencrypted, actualKey.GetBitcoinSecret(Network.Main).ToString());
				Assert.Equal(test.Address, actualKey.PubKey.GetAddress(Network.Main).ToString());
				Assert.Equal(test.Compressed, actualKey.IsCompressed);


				//Can generate same BitcoinPassphraseCode with by using same ownerentropy
				var passCode = new BitcoinPassphraseCode(test.PassphraseCode, Network.Main);
				Assert.Null(passCode.LotSequence);
				var actualPassCode = new BitcoinPassphraseCode(test.Passphrase, Network.Main, null, passCode.OwnerEntropy);
				Assert.Equal(passCode.ToString(), actualPassCode.ToString());

				//Can generate encrypted key from passcode
				var generatedEncryptedKey = passCode.GenerateEncryptedSecret(test.Compressed).EncryptedKey;
				AssertEx.CollectionEquals(passCode.OwnerEntropy, generatedEncryptedKey.OwnerEntropy);
				Assert.Equal(test.Compressed, generatedEncryptedKey.IsCompressed);
			}
		}
示例#6
0
		public void EncryptedSecretECmultiplyLotSequence()
		{
			var tests = new[]
			{
				new {
				Passphrase= "ΜΟΛΩΝ ΛΑΒΕ",
				PassphraseCode= "passphrased3z9rQJHSyBkNBwTRPkUGNVEVrUAcfAXDyRU1V28ie6hNFbqDwbFBvsTK7yWVK",
				Encrypted = "6PgGWtx25kUg8QWvwuJAgorN6k9FbE25rv5dMRwu5SKMnfpfVe5mar2ngH",
				Address = "1Lurmih3KruL4xDB5FmHof38yawNtP9oGf",
				Unencrypted = "5KMKKuUmAkiNbA3DazMQiLfDq47qs8MAEThm4yL8R2PhV1ov33D",
				ConfirmationCode = "cfrm38V8G4qq2ywYEFfWLD5Cc6msj9UwsG2Mj4Z6QdGJAFQpdatZLavkgRd1i4iBMdRngDqDs51",
				LotSequence = new LotSequence(806938,1),
				Compressed = false
				}
				,new {
				Passphrase= "MOLON LABE",
				PassphraseCode= "passphraseaB8feaLQDENqCgr4gKZpmf4VoaT6qdjJNJiv7fsKvjqavcJxvuR1hy25aTu5sX",
				Encrypted = "6PgNBNNzDkKdhkT6uJntUXwwzQV8Rr2tZcbkDcuC9DZRsS6AtHts4Ypo1j",
				Address = "1Jscj8ALrYu2y9TD8NrpvDBugPedmbj4Yh",
				Unencrypted = "5JLdxTtcTHcfYcmJsNVy1v2PMDx432JPoYcBTVVRHpPaxUrdtf8",
				ConfirmationCode = "cfrm38V8aXBn7JWA1ESmFMUn6erxeBGZGAxJPY4e36S9QWkzZKtaVqLNMgnifETYw7BPwWC9aPD",
				LotSequence = new LotSequence(263183,1),
				Compressed = false
				}
			};

			foreach(var test in tests)
			{
				//Can generate unencrypted key with password and encrypted key
				var encryptedKey = new BitcoinEncryptedSecretEC(test.Encrypted, Network.Main);
				AssertSequenceEquals(test.LotSequence, encryptedKey.LotSequence);
				var actualKey = encryptedKey.GetKey(test.Passphrase);
				Assert.Equal(test.Unencrypted, actualKey.GetBitcoinSecret(Network.Main).ToString());
				Assert.Equal(test.Address, actualKey.PubKey.GetAddress(Network.Main).ToString());
				Assert.Equal(test.Compressed, actualKey.IsCompressed);


				//Can generate same BitcoinPassphraseCode with by using same ownerentropy
				var passCode = new BitcoinPassphraseCode(test.PassphraseCode, Network.Main);
				AssertSequenceEquals(test.LotSequence, passCode.LotSequence);
				var actualPassCode = new BitcoinPassphraseCode(test.Passphrase, Network.Main, test.LotSequence, passCode.OwnerEntropy);
				Assert.Equal(passCode.ToString(), actualPassCode.ToString());

				//Can verify confirmation
				var confirmation = new BitcoinConfirmationCode(test.ConfirmationCode, Network.Main);
				AssertSequenceEquals(confirmation.LotSequence, test.LotSequence);
				Assert.True(confirmation.Check(test.Passphrase, new BitcoinAddress(test.Address, Network.Main)));

				//Can generate encrypted key from passcode
				var generatedEncryptedKey = passCode.GenerateEncryptedSecret(test.Compressed).EncryptedKey;
				AssertEx.CollectionEquals(passCode.OwnerEntropy, generatedEncryptedKey.OwnerEntropy);
				Assert.Equal(test.Compressed, generatedEncryptedKey.IsCompressed);
			}
		}
示例#7
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxKey.Text))
            {
                MessageBox.Show(this, "Enter a key.", "Knoledge-keychain", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            using (new HourGlass())
            {
                Result = Util.InterpretKey(textBoxKey.Text);
            }

            if (Result == null)
            {
                MessageBox.Show(this, "Unrecognized or invalid key.", "Knoledge-keychain", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                using (new HourGlass())
                {
                    Type type = Result.GetType();
                    switch (type.ToString())
                    {
                    case "NBitcoin.BitcoinEncryptedSecretEC":
                        if (string.IsNullOrEmpty(textBoxPassword.Text))
                        {
                            MessageBox.Show(this, "This is an encrypted BitcoinSecret, please provide the password.", "Knoledge-keychain", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }
                        else
                        {
                            try
                            {
                                BitcoinEncryptedSecretEC encEC = Result as BitcoinEncryptedSecretEC;
                                Result       = encEC.GetKey(textBoxPassword.Text).GetBitcoinSecret(Network.TestNet);
                                DialogResult = System.Windows.Forms.DialogResult.OK;
                            }
                            catch
                            {
                                MessageBox.Show(this, "The pasword you entered is incorrect.", "Knoledge-keychain", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        break;

                    case "NBitcoin.BitcoinEncryptedSecretNoEC":
                        if (string.IsNullOrEmpty(textBoxPassword.Text))
                        {
                            MessageBox.Show(this, "This is an encrypted BitcoinSecret, please provide the password.", "Knoledge-keychain", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }
                        else
                        {
                            try
                            {
                                BitcoinEncryptedSecretNoEC encEC = Result as BitcoinEncryptedSecretNoEC;
                                Result       = encEC.GetKey(textBoxPassword.Text).GetBitcoinSecret(Network.TestNet);
                                DialogResult = System.Windows.Forms.DialogResult.OK;
                            }
                            catch
                            {
                                MessageBox.Show(this, "The pasword you entered is incorrect.", "Knoledge-keychain", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        break;

                    case "NBitcoin.BitcoinPassphraseCode":
                        if (string.IsNullOrEmpty(textBoxPassword.Text))
                        {
                            MessageBox.Show(this, "This is a PassphraseCode, please provide the password.", "Knoledge-keychain", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }
                        else
                        {
                            try
                            {
                                BitcoinPassphraseCode phrase = Result as BitcoinPassphraseCode;
                                EncryptedKeyResult    key    = phrase.GenerateEncryptedSecret();

                                if (key.ConfirmationCode.Check(textBoxPassword.Text, key.GeneratedAddress))
                                {
                                    BitcoinSecret secret = key.EncryptedKey.GetSecret(textBoxPassword.Text);
                                    if (secret.GetAddress() == key.GeneratedAddress)
                                    {
                                        Result       = secret;
                                        DialogResult = System.Windows.Forms.DialogResult.OK;
                                    }
                                    else
                                    {
                                        MessageBox.Show(this, "The Generated Addresses do not match.", "Knoledge-keychain", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    }
                                }
                                else
                                {
                                    MessageBox.Show(this, "The Confirmation Code check failed.", "Knoledge-keychain", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                            catch
                            {
                                MessageBox.Show(this, "The password you entered is incorrect.", "Knoledge-keychain", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        break;

                    default:
                        DialogResult = System.Windows.Forms.DialogResult.OK;
                        break;
                    }
                }
            }
        }