private void GeneratorThread()
        {
            var key = PrivateKey.Generate(2048);

            privateKey = key.ToXmlString();
            publicKey  = key.GetPublicKey().ToXmlString();
        }
        public void EncryptTest()
        {
            var prvKey    = PrivateKey.Generate();
            var pubKey    = prvKey.PublicKey;
            var bs        = Encoding.ASCII.GetBytes("hello world");
            var encrypted = pubKey.Encrypt(bs);

            CollectionAssert.AreEqual(bs, prvKey.Decrypt(encrypted));
        }
Beispiel #3
0
        public static void Main(string[] args, KeyStorage keyStorage)
        {
            Console.WriteLine("Keys");

            if (args.Length == 1)
            {
                Console.WriteLine();
                Console.WriteLine("Public keys:");
                foreach (PublicKey pub in keyStorage.PublicKeys)
                {
                    Console.WriteLine("	" + pub);
                }
                Console.WriteLine();
                Console.WriteLine("Private keys:");
                foreach (PrivateKey priv in keyStorage.PrivateKeys)
                {
                    Console.WriteLine("	" + priv.ToString());
                }
                Console.WriteLine();

                return;
            }

            if (args.Length == 3 && args [1] == "generate")
            {
                PrivateKey key  = PrivateKey.Generate();
                string     name = Path.GetFileName(args [2]);
                keyStorage.Add(name, key);

                Console.WriteLine();
                Console.WriteLine("New key: " + name);
                Console.WriteLine(key.ToString());
                Console.WriteLine();

                return;
            }

            throw new HelpException("Missing arguments");
        }
Beispiel #4
0
        public static void Main(string[] args)
        {
            var pk = PrivateKey.Generate();

            Console.WriteLine(pk.ToHex());

            var privateKeyHex = "ff2ba092524bafdbc85fa0c7eddb2b41c69bc9bf066a4711a8a16f749199e5be";
            var pk2           = new PrivateKey(privateKeyHex);
            var generatedPk   = pk2.ToHex();

            if (generatedPk == privateKeyHex)
            {
                Console.WriteLine("Right!");
                Console.WriteLine(pk2.ToHex());
            }
            else
            {
                Console.WriteLine("Private key wrong!");
            }

            var publicKey  = pk2.PublicKey;
            var pkHex      = "04ad4793d81c5ee6c91c4baf2689c5299276c4774a8625fa87257f62ba8f3fe31f79d1351bd83af800afdaa94d40fe46c969f0ce2ac2e03e45d5a2d8a7687c39c0";
            var publicKey2 = new PublicKey(pkHex);

            if (publicKey2.ToHex() == pkHex)
            {
                Console.WriteLine("Right!");
                Console.WriteLine(publicKey2.ToHex());
            }
            else
            {
                Console.WriteLine("Public key wrong!");
            }

            var ethAddress = publicKey2.EthAddress;
            var revAddress = publicKey2.RevAddress;
            //sign example
        }
Beispiel #5
0
 public void GenerateTest()
 {
     PrivateKey.Generate();
 }