static public void SelfTest() { NDEA dea = new NDEA(); dea.SetStringKey("hello!"); var code = dea.EnCrypto("hello world!"); Debug.Log(dea.DeCryptoString(code)); dea.SetStringKey("World"); Debug.Log(dea.DeCryptoString(code)); }
public string ExportSecKey(string userKey) { var md5 = Utils.GetMD5(Encoding.ASCII.GetBytes(userKey)); if (!PasswordEquals(md5, dat.userKeyMD5)) { return(string.Empty); } var dea = new NDEA(); dea.SetStringKey(userKey); var mainKey = dea.DeCrypto(dat.mainKeyCrypto); dea.SetKey(mainKey); return(Utils.Byte2HexStr(dea.DeCrypto(dat.secKeyCrypto))); }
public bool ImportKey(string userKey, string secKeyHexString) { dat.userKeyMD5 = Utils.GetMD5(Encoding.ASCII.GetBytes(userKey)); if (secKeyHexString.Length != 64) { return(false); } var secKey = Utils.HexStr2Byte(secKeyHexString); var mainKey = NDEA.GenerateKey(); var dea = new NDEA(); dea.SetStringKey(userKey); dat.mainKeyCrypto = dea.EnCrypto(mainKey); dea.SetKey(mainKey); dat.secKeyCrypto = dea.EnCrypto(secKey); dat.address = NECDsa.getEthAddress(secKeyHexString); dat.Save(); return(true); }
void Start() { NixLib.NWallet.SelfTest(); Debug.Log(NixLib.NMnemonicWord.SelfTest()); NDEA.SelfTest(); Debug.Log(Utils.SelfTest()); Debug.Log(NECDsa.SelfTest()); cmUI = GetComponent <CrazyMinerUI>(); cm = GetComponent <CrazyMiner>(); if (PlayerPrefs.HasKey("SecKey")) { keyPair.pri = PlayerPrefs.GetString("SecKey"); keyPair.pub = PlayerPrefs.GetString("PubKey"); keyPair.addr = PlayerPrefs.GetString("Addr"); } else { dsa.Generate(); keyPair.pri = dsa.secKeyStr; keyPair.pub = dsa.pubKeyStr.ToUpper(); keyPair.addr = dsa.ethAddrStr; PlayerPrefs.SetString("SecKey", keyPair.pri); PlayerPrefs.SetString("PubKey", keyPair.pub); PlayerPrefs.SetString("Addr", keyPair.addr); } onnReq.Init(keyPair.pri); onnReq.SetUrlContract(httpAddr, contract); Debug.Log(JsonUtility.ToJson(keyPair)); InvokeRepeating("Tick", 0.3f, 1f); }