Example #1
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 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);
        }