Пример #1
0
        public static EcKey createEcKeyFromHexString(String privateKey)
        {
            BigInteger pkey = new BigInteger(privateKey, 16);
            EcKey      key  = new EcKey(pkey);

            return(key);
        }
Пример #2
0
        //public static EcKey loadEcKey()
        //{
        //    using (FileStream fs = File.OpenRead(PRIV_KEY_FILENAME))
        //    {
        //        byte[] b = new byte[1024];
        //        fs.Read(b, 0, b.Length);
        //        string base58 = new Base58Encoding().Encode(b);
        //        Debug.Log("loadEcKey():Base58 of prvkey:" + base58);
        //        EcKey key = EcKey.FromAsn1(b);
        //        return key;
        //    }
        //}

        public static Key loadNBEcKey()
        {
            string base58 = ResourcesDataAccess.Load();

            byte[] b   = new Base58Encoding().Decode(base58);
            EcKey  key = EcKey.FromAsn1(b);

            return(new Key(key.GetPrivKeyBytes()));
        }
Пример #3
0
        //public static void saveEcKey(EcKey ecKey)
        //{
        //    byte[] bytes = ecKey.ToAsn1();
        //    FileStream fs = new FileStream(PRIV_KEY_FILENAME, FileMode.Create, FileAccess.Write);
        //    fs.Write(bytes, 0, bytes.Length);
        //    fs.Close();
        //}

        public static void saveEcKey(Key nbEcKey)
        {
            Debug.Log("saveEcKey():start");

            byte[] bytes  = EcKey.ToAsn1(nbEcKey.ToBytes(), nbEcKey.PubKey.ToBytes());
            string base58 = new Base58Encoding().Encode(bytes);

            ResourcesDataAccess.Save(base58);
            Debug.Log("saveEcKey():end");
        }
Пример #4
0
        public static string sign(EcKey ecKey, string input)
        {
            // return ecKey.Sign(input);
            String hash      = Sha256Hash(input);
            var    hashBytes = hexToBytes(hash);
            var    signature = ecKey.Sign(hashBytes);
            var    bytesHex  = bytesToHex(signature);

            return(bytesHex);
            //return bytesToHex(ecKey.Sign(hexToBytes(hash)));
        }
Пример #5
0
        //public static void saveEcKey(Key nbEcKey)
        //{
        //    Debug.Log("saveEcKey():start");

        //    byte[] bytes = EcKey.ToAsn1(nbEcKey.ToBytes(), nbEcKey.PubKey.ToBytes());
        //    string base58 = new Base58Encoding().Encode(bytes);

        //    DataAccess.Save(base58);
        //    Debug.Log("saveEcKey():end");
        //}
        //public static void saveEcKey(Key nbEcKey)
        //{
        //    Debug.Log("saveEcKey():start");

        //    byte[] bytes = EcKey.ToAsn1(nbEcKey.ToBytes(), nbEcKey.PubKey.ToBytes());
        //    FileStream fs = new FileStream(PRIV_KEY_FILENAME, FileMode.Create, FileAccess.Write);
        //    fs.Write(bytes, 0, bytes.Length);
        //    fs.Close();
        //    Debug.Log("saveEcKey():end");
        //}

        public static String deriveSIN(EcKey ecKey)
        {
            byte[] pubKey = ecKey.PubKey;
            return(deriveSIN(pubKey));
        }