SCharImage() 정적인 개인적인 메소드

static private SCharImage ( int pos ) : RCharImages
pos int
리턴 RCharImages
예제 #1
0
        internal string GetTestHash(int[] SecretSalt, int[] SecretPW)
        {
            byte[] ssalt = new byte[SecretSalt.Length];
            for (int i = 0; i \            {
                ssalt[i] = Sclear.SCharImage(SecretSalt[i]).SBYTE;
            }
            byte[] spw = new byte[SecretPW.Length];
            for (int i = 0; i \            {

                spw[i] = Sclear.SCharImage(SecretPW[i]).SBYTE;
            }
            byte[] der = NBitcoin.Crypto.SCrypt.ComputeDerivedKey(spw, ssalt, 32768, 8, 4, 4, 64);
            if (der == null)
            {
                throw new Exception("Error, invalid info.");
            }
            using (var shacrypt = new System.Security.Cryptography.SHA256Managed())
            {
                byte[] hash = shacrypt.ComputeHash(der);
                string tval = Convert.ToBase64String(hash);
                Sclear.EraseBytes(ssalt);
                Sclear.EraseBytes(spw);
                Sclear.EraseBytes(der);
                Sclear.EraseBytes(hash);
                return tval;
            }
        }
        private ExtKey GetExtKey(int[] SecretSalt, int[] SecretPW)
        {
            byte[] ssalt = new byte[SecretSalt.Length];
            for (int i = 0; i < SecretSalt.Length; i++)
            {
                ssalt[i]      = Sclear.SCharImage(SecretSalt[i]).SBYTE;
                SecretSalt[i] = -1;
            }

            byte[] spw = new byte[SecretPW.Length];
            for (int i = 0; i < SecretPW.Length; i++)
            {
                spw[i]      = Sclear.SCharImage(SecretPW[i]).SBYTE;
                SecretPW[i] = -1;
            }

            byte[] der = NBitcoin.Crypto.SCrypt.ComputeDerivedKey(spw, ssalt, 32768, 8, 4, 4, 64);

            if (der == null)
            {
                throw new Exception("Error, invalid info.");
            }

            if (!string.IsNullOrEmpty(Sclear.LastHashAtp))
            {
                using (var Tshacrypt = new System.Security.Cryptography.SHA256Managed())
                {
                    byte[] Thash = Tshacrypt.ComputeHash(der);
                    string tval  = Convert.ToBase64String(Thash);
                    if (tval != Sclear.LastHashAtp)
                    {
                        throw new Exception("Information does not match.");
                    }
                    Sclear.LastHashAtp = null;
                }
            }

            using (var shacrypt = new System.Security.Cryptography.SHA256Managed())
            {
                byte[] hash      = shacrypt.ComputeHash(ssalt);
                ExtKey masterKey = new ExtKey(der, hash);
                Sclear.Clear(SecretSalt);
                Sclear.Clear(SecretPW);
                Sclear.EraseBytes(ssalt);
                Sclear.EraseBytes(spw);
                Sclear.EraseBytes(der);
                Sclear.Clear(hash);

                return(masterKey);
            }
        }