Esempio n. 1
0
 public static byte[] encryptData(byte[] data, byte[] key)
 {
     char[] array  = BaseFunctions.HexEncoder(data).ToCharArray();
     byte[] array2 = new byte[array.Length];
     for (int i = 0; i < array.Length; i++)
     {
         array2[i] = (byte)array[i];
     }
     return(HOTPCipher.encrypt(array2, key));
 }
Esempio n. 2
0
 public static byte[] encryptData(byte[] data, byte[] key)
 {
     char[] chArray = BaseFunctions.HexEncoder(data).ToCharArray();
     byte[] buffer  = new byte[chArray.Length];
     for (int i = 0; i < chArray.Length; i++)
     {
         buffer[i] = (byte)chArray[i];
     }
     return(HOTPCipher.encrypt(buffer, key));
 }
Esempio n. 3
0
        public static OperationResult TokensCreateNew(TokenTypeBaseParams tkTypeBaseParams, string masterKey, string vendorSerialNumber, string dataEntropy, out TokenCryptoData tokenCryptoData)
        {
            OperationResult result;

            try
            {
                byte[] data;
                byte[] data2;
                long   movingFactor;
                if (OperationResult.Error == HOTPCryptoData.Generate(masterKey, null, tkTypeBaseParams, out data, out data2, out movingFactor))
                {
                    tokenCryptoData = new TokenCryptoData(null, null, default(CryptoData), default(TokenTypeBaseParams));
                    result          = OperationResult.Error;
                }
                else
                {
                    TokenCryptoData tokenCryptoData2 = new TokenCryptoData(null, vendorSerialNumber, new CryptoData(movingFactor, BaseFunctions.HexEncoder(data), BaseFunctions.HexEncoder(data2), ""), tkTypeBaseParams);
                    tokenCryptoData2.ResetMovingFactor(HOTPCipherInitialize.createSequenceNumber());

                    /*--------------------------*/
                    byte[]        tokenSeed = tokenCryptoData2.GetTokenSeed(masterKey);
                    string        x         = Encoding.ASCII.GetString(tokenSeed);
                    Base32Encoder enc       = new Base32Encoder();
                    string        y         = enc.Encode(tokenSeed);


                    /*--------------------------*/


                    if (tkTypeBaseParams.MovingFactorType == TokenMovingFactorType.TransactionAuthenticationNumber)
                    {
                        string value;
                        if (OperationResult.Error == TokensBaseFunctions.tokenTANMatrixIntegrityCheck(tokenCryptoData2, tokenCryptoData2.GetTokenSeed(masterKey), (dataEntropy == null || dataEntropy.Length < 1) ? new byte[0] : BaseFunctions.convertStringToByteArray(dataEntropy), out value))
                        {
                            tokenCryptoData = new TokenCryptoData(null, null, default(CryptoData), default(TokenTypeBaseParams));
                            result          = OperationResult.Error;
                            return(result);
                        }
                        tokenCryptoData2.ResetSupportCryptoData(value);
                    }
                    tokenCryptoData = tokenCryptoData2;
                    result          = OperationResult.Success;
                }
            }
            catch
            {
                LOGGER.Write(LOGGER.LogCategory.ERROR, "SF.Expand.SAF.Core::TokensCreateNew[]", null);
                tokenCryptoData = new TokenCryptoData(null, null, default(CryptoData), default(TokenTypeBaseParams));
                result          = OperationResult.Error;
            }
            return(result);
        }
        public static byte[] createCryptKey(byte[] serialNumber, string pin)
        {
            string text = BaseFunctions.HexEncoder(serialNumber);

            return(HashBaseFunction.createBinaryHash(text.Substring(text.Length - 4, 4) + pin + text.Substring(0, 2)));
        }
        public static OperationResult TokensCreateNew(TokenTypeBaseParams tkTypeBaseParams, string masterKey, string vendorSerialNumber, string dataEntropy, out TokenCryptoData tokenCryptoData)
        {
            OperationResult result;

            try
            {
                byte[] tkseed;
                byte[] tkserial;
                long   tkmovFactor;
                if (OperationResult.Error == HOTPCryptoData.Generate(masterKey, null, tkTypeBaseParams, out tkseed, out tkserial, out tkmovFactor))
                {
                    tokenCryptoData = new TokenCryptoData(null, null, new CryptoData(), new TokenTypeBaseParams());
                    result          = OperationResult.Error;
                }
                else
                {
                    TokenCryptoData _tkCryptoData = new TokenCryptoData(null, vendorSerialNumber, new CryptoData(tkmovFactor, BaseFunctions.HexEncoder(tkseed), BaseFunctions.HexEncoder(tkserial), ""), tkTypeBaseParams);
                    _tkCryptoData.ResetMovingFactor(HOTPCipherInitialize.createSequenceNumber());
                    if (tkTypeBaseParams.MovingFactorType == TokenMovingFactorType.TransactionAuthenticationNumber)
                    {
                        string supportCryptoData;
                        if (OperationResult.Error == TokensBaseFunctions.tokenTANMatrixIntegrityCheck(_tkCryptoData, _tkCryptoData.GetTokenSeed(masterKey), (dataEntropy == null || dataEntropy.Length < 1) ? new byte[0] : BaseFunctions.convertStringToByteArray(dataEntropy), out supportCryptoData))
                        {
                            tokenCryptoData = new TokenCryptoData(null, null, new CryptoData(), new TokenTypeBaseParams());
                            result          = OperationResult.Error;
                            return(result);
                        }
                        _tkCryptoData.ResetSupportCryptoData(supportCryptoData);
                    }
                    tokenCryptoData = _tkCryptoData;
                    result          = OperationResult.Success;
                }
            }
            catch (Exception ex)
            {
                tokenCryptoData = new TokenCryptoData(null, null, default(CryptoData), default(TokenTypeBaseParams));
                SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFCORE", new string[]
                {
                    "http://sfexpand.SAFCore.TokensBaseFunctions.softfinanca.com/",
                    Assembly.GetExecutingAssembly().FullName.ToString(),
                    ex.ToString()
                });
                result = OperationResult.Error;
            }
            finally
            {
                // byte[] tkseed = null;
                // byte[] tkserial = null;
            }
            return(result);
        }
        public static OperationResult TokensImportNew(TokenTypeBaseParams tkTypeBaseParams, string masterKey, string vendorSerialNumber, string externalSeed, string pin, long movingFactor, out TokenCryptoData TokenCryptoData)
        {
            TokenCryptoData = new TokenCryptoData(null, null, new CryptoData(), new TokenTypeBaseParams());
            OperationResult result;

            try
            {
                if (tkTypeBaseParams.SeedType != TokenSeedType.Dynamic)
                {
                    throw new Exception("Invalid Seed type!");
                }
                if (tkTypeBaseParams.MovingFactorType != TokenMovingFactorType.EventBase || movingFactor < 1L)
                {
                    throw new Exception("Invalid MovingFactorType!");
                }
                byte[] tkserial = HOTPCipherInitialize.createSerialNumber((pin == null || pin.Length < 1) ? HOTPCipherInitialize.Generate4DigitsPin() : pin);
                byte[] tkseed   = HOTPCipher.encryptData(BaseFunctions.HexDecoder(externalSeed), HOTPCipherInitialize.createCryptKey(tkserial, (masterKey == null || masterKey.Length < 1) ? new byte[0] : BaseFunctions.convertStringToByteArray(masterKey)));
                TokenCryptoData = new TokenCryptoData(null, vendorSerialNumber, new CryptoData(movingFactor, BaseFunctions.HexEncoder(tkseed), BaseFunctions.HexEncoder(tkserial), ""), tkTypeBaseParams);
                TokenCryptoData.ResetMovingFactor(movingFactor);
                result = OperationResult.Success;
            }
            catch (Exception ex)
            {
                TokenCryptoData = new TokenCryptoData(null, null, new CryptoData(), new TokenTypeBaseParams());
                SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFCORE", new string[]
                {
                    "http://sfexpand.SAFCore.TokensBaseFunctions.softfinanca.com/",
                    Assembly.GetExecutingAssembly().FullName.ToString(),
                    ex.ToString()
                });
                result = OperationResult.Error;
            }
            finally
            {
            }
            return(result);
        }
Esempio n. 7
0
        public bool Export(string pin, string deviceType, string masterKey, TokenCryptoData tokenCryptoData, out string tokenBlob)
        {
            tokenBlob = null;
            bool result;

            try
            {
                if (pin == null || pin.Length < 4 || deviceType == null || deviceType.Length != 2)
                {
                    result = false;
                }
                else
                {
                    byte[] blob        = new byte[114];
                    byte[] cryptoBlock = new byte[48];
                    byte[] _oTPOffSet  = new byte[]
                    {
                        (byte)tokenCryptoData.TokenBaseParams.OTPOffSet
                    };
                    byte[] _oTPTotalDigits = new byte[]
                    {
                        (byte)tokenCryptoData.TokenBaseParams.OTPTotalDigits
                    };
                    byte[] _movingFactorType = new byte[]
                    {
                        (byte)tokenCryptoData.TokenBaseParams.MovingFactorType
                    };
                    byte[] _hOTPMovingFactorDrift = new byte[]
                    {
                        (byte)tokenCryptoData.TokenBaseParams.HOTPMovingFactorDrift
                    };
                    byte[] _dvType = new byte[]
                    {
                        (char.Parse(deviceType.Substring(0, 1)) <= '9' && char.Parse(deviceType.Substring(0, 1)) >= '0') ? byte.Parse(deviceType.Substring(0, 1)) : ((byte)char.Parse(deviceType.Substring(0, 1))),
                        (char.Parse(deviceType.Substring(1, 1)) <= '9' && char.Parse(deviceType.Substring(1, 1)) >= '0') ? byte.Parse(deviceType.Substring(1, 1)) : ((byte)char.Parse(deviceType.Substring(1, 1)))
                    };
                    byte[] _pin          = HashBaseFunction.createBinaryHash(BaseFunctions.convertStringToByteArray(pin));
                    byte[] _movingFactor = BitConverter.GetBytes(tokenCryptoData.CryptoData.MovingFactor);
                    byte[] _serialNumber = BaseFunctions.HexDecoder(tokenCryptoData.CryptoData.InternalSerialNumber);
                    byte[] _internalKey  = tokenCryptoData.GetTokenSeed(masterKey);
                    Buffer.BlockCopy(_internalKey, 0, cryptoBlock, 0, 32);
                    Buffer.BlockCopy(_movingFactor, 0, cryptoBlock, 32, 8);
                    Buffer.BlockCopy(_oTPTotalDigits, 0, cryptoBlock, 40, 1);
                    Buffer.BlockCopy(_oTPOffSet, 0, cryptoBlock, 41, 1);
                    Buffer.BlockCopy(_movingFactorType, 0, cryptoBlock, 42, 1);
                    Buffer.BlockCopy(_hOTPMovingFactorDrift, 0, cryptoBlock, 43, 1);
                    Buffer.BlockCopy(_dvType, 0, blob, 0, 2);
                    Buffer.BlockCopy(_pin, 0, blob, 2, 32);
                    Buffer.BlockCopy(_serialNumber, 0, blob, 34, 32);
                    Buffer.BlockCopy(HOTPCipher.encrypt(cryptoBlock, HOTPCipherInitialize.createCryptKey(_serialNumber, pin)), 0, blob, 66, 48);
                    tokenBlob = BaseFunctions.HexEncoder(blob);
                    result    = true;
                }
            }
            catch (Exception ex)
            {
                SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFCORE", new string[]
                {
                    "http://sfexpand.SAFCore.BLOBStructInfSrv.softfinanca.com/",
                    Assembly.GetExecutingAssembly().FullName.ToString(),
                    ex.ToString()
                });
                tokenBlob = null;
                result    = false;
            }
            return(result);
        }
Esempio n. 8
0
        public static byte[] createCryptKey(byte[] serialNumber)
        {
            string _str = BaseFunctions.HexEncoder(serialNumber);

            return(HashBaseFunction.createBinaryHash(_str.Substring(serialNumber.Length - 4) + _str.Substring(0, 6)));
        }