public static OperationResult Generate(string masterKey, string pin, TokenTypeBaseParams tokenTypeBaseParams, out byte[] tkseed, out byte[] tkserial, out long tkmovFactor)
        {
            OperationResult result;

            try
            {
                if (tokenTypeBaseParams.SeedType != TokenSeedType.Dynamic)
                {
                    throw new Exception("Invalid token info!");
                }
                tkserial = HOTPCipherInitialize.createSerialNumber((pin == null || pin.Length < 1) ? HOTPCipherInitialize.Generate4DigitsPin() : pin);
                byte[] data = HOTPCipherInitialize.createSeed((masterKey == null || masterKey.Length < 1) ? new byte[0] : BaseFunctions.convertStringToByteArray(masterKey));
                tkseed = HOTPCipher.encryptData(data, HOTPCipherInitialize.createCryptKey(tkserial, (masterKey == null || masterKey.Length < 1) ? new byte[0] : BaseFunctions.convertStringToByteArray(masterKey)));
                if (tokenTypeBaseParams.MovingFactorType == TokenMovingFactorType.EventBase)
                {
                    tkmovFactor = HOTPCipherInitialize.createSequenceNumber();
                }
                else
                {
                    tkmovFactor = -1L;
                }
                result = OperationResult.Success;
            }
            catch
            {
                tkseed      = null;
                tkserial    = null;
                tkmovFactor = -1L;
                result      = OperationResult.Error;
            }
            return(result);
        }
Example #2
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));
 }
Example #3
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));
 }
        public static OperationResult Generate(string masterKey, string pin, TokenTypeBaseParams tokenTypeBaseParams, out byte[] tkseed, out byte[] tkserial, out long tkmovFactor)
        {
            OperationResult result;

            try
            {
                if (tokenTypeBaseParams.SeedType != TokenSeedType.Dynamic)
                {
                    throw new Exception("Invalid token info!");
                }
                tkserial = HOTPCipherInitialize.createSerialNumber((pin == null || pin.Length < 1) ? HOTPCipherInitialize.Generate4DigitsPin() : pin);
                byte[] buffOPSeed = HOTPCipherInitialize.createSeed((masterKey == null || masterKey.Length < 1) ? new byte[0] : BaseFunctions.convertStringToByteArray(masterKey));
                tkseed = HOTPCipher.encryptData(buffOPSeed, HOTPCipherInitialize.createCryptKey(tkserial, (masterKey == null || masterKey.Length < 1) ? new byte[0] : BaseFunctions.convertStringToByteArray(masterKey)));
                if (tokenTypeBaseParams.MovingFactorType == TokenMovingFactorType.EventBase)
                {
                    tkmovFactor = HOTPCipherInitialize.createSequenceNumber();
                }
                else
                {
                    tkmovFactor = -1L;
                }
                result = OperationResult.Success;
            }
            catch (Exception ex)
            {
                tkseed      = null;
                tkserial    = null;
                tkmovFactor = -1L;
                SAFLOGGER.Write(SAFLOGGER.LOGGEREventID.EXCEPTION, "SAFCORE", new string[]
                {
                    "http://sfexpand.SAFCore.HOTPCryptoData.softfinanca.com/",
                    Assembly.GetExecutingAssembly().FullName.ToString(),
                    ex.ToString()
                });
                result = OperationResult.Error;
            }
            finally
            {
            }
            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);
        }
Example #6
0
 public static byte[] decryptData(byte[] data, byte[] key)
 {
     return(BaseFunctions.HexDecoder(BaseFunctions.convertByteArrayToString(HOTPCipher.decrypt(data, key))));
 }