Esempio n. 1
0
        public byte[] createPinAuthforChangePin(byte[] sharedSecret, string newpin, string currentpin)
        {
            // new pin
            byte[] newPinEnc = null;
            {
                var newpin64 = this.paddingPin64(newpin);
                newPinEnc = AES256CBC.Encrypt(sharedSecret, newpin64);
            }

            // current pin
            var currentPinHashEnc = createPinHashEnc(currentpin, sharedSecret);

            // source data
            var data = new List <byte>();

            data.AddRange(newPinEnc.ToArray());
            data.AddRange(currentPinHashEnc.ToArray());

            // HMAC-SHA-256(sharedSecret, newPinEnc)
            byte[] pinAuth;
            using (var hmacsha256 = new HMACSHA256(sharedSecret)) {
                var dgst = hmacsha256.ComputeHash(data.ToArray());
                pinAuth = dgst.ToList().Take(16).ToArray();
            }
            return(pinAuth);
        }
Esempio n. 2
0
        public byte[] createPinAuthforSetPin(byte[] sharedSecret, string newpin)
        {
            var newpin64 = this.paddingPin64(newpin);

            var newPinEnc = AES256CBC.Encrypt(sharedSecret, newpin64);

            // HMAC-SHA-256(sharedSecret, newPinEnc)
            byte[] pinAuth;
            using (var hmacsha256 = new HMACSHA256(sharedSecret)) {
                var dgst = hmacsha256.ComputeHash(newPinEnc);
                pinAuth = dgst.ToList().Take(16).ToArray();
            }
            return(pinAuth);
        }
Esempio n. 3
0
        public byte[] createPinHashEnc(string pin, byte[] sharedSecret)
        {
            // AES256-CBC(sharedSecret, IV=0, LEFT(SHA-256(PIN), 16))

            // pinsha = SHA-256(PIN) ->32byte
            byte[] pinbyte = Encoding.ASCII.GetBytes(pin);
            SHA256 sha     = new SHA256CryptoServiceProvider();

            byte[] pinsha = sha.ComputeHash(pinbyte);

            // pinsha16 = LEFT 16(pinsha)
            byte[] pinsha16 = pinsha.ToList().Skip(0).Take(16).ToArray();

            // pinHashEnc = AES256-CBC(sharedSecret, IV=0, pinsha16)
            string key  = Common.BytesToHexString(sharedSecret);
            string data = Common.BytesToHexString(pinsha16);

            var pinHashEnc = AES256CBC.Encrypt(sharedSecret, pinsha16);

            return(pinHashEnc);
        }
Esempio n. 4
0
 // newPinEnc: AES256-CBC(sharedSecret, IV = 0, newPin)
 public byte[] createNewPinEnc(byte[] sharedSecret, byte[] newpin64)
 {
     byte[] newPinEnc = AES256CBC.Encrypt(sharedSecret, newpin64);
     return(newPinEnc);
 }