public EntityComparer( string entityName, IKeyProvider <Entity> keyProvider, bool onlyActiveRecords) : this(entityName, keyProvider, Skip.Nothing, onlyActiveRecords) { }
/// <summary> /// Unregister a key provider so it is not querried for keys anymore. /// </summary> /// <param name="provider">The provider to unregister.</param> public void UnregisterProvider(IKeyProvider provider) { if (provider != null) { keyProvider.Remove(provider); } }
public UploadController(IFileCabinet fileCabinet, IUploadValidator uploadValidator, IKeyProvider keyProvider, IPathMapper pathMapper) { this.fileCabinet = fileCabinet; this.uploadValidator = uploadValidator; this.keyProvider = keyProvider; this.pathMapper = pathMapper; }
/// <summary> /// Create a HOTP instance /// </summary> /// <param name="key">The key to use in HOTP calculations</param> /// <param name="mode">The hash mode to use</param> /// <param name="hotpSize">The number of digits that the returning HOTP should have. The default is 6.</param> public Hotp(IKeyProvider key, OtpHashMode mode = OtpHashMode.Sha1, int hotpSize = 6) : base(key, mode) { VerifyParameters(hotpSize); this.hotpSize = hotpSize; }
public MessageProvider(IShortcutProvider shortcutProvider, IKeyProvider keyProvider, PopupSettings settings, IMessageMerger messageMerger) { this.shortcutProvider = shortcutProvider; this.keyProvider = keyProvider; this.messageMerger = messageMerger; this.settings = settings; }
/// <summary> /// Gets a Security Session. /// </summary> /// <param name="securitySessionName">The name of the Security Session.</param> /// <param name="keyStore">The store of all keys.</param> /// <returns>An object implementing ISecuritySession interface.</returns> public SecuritySession GetSecuritySession(string securitySessionName, IKeyStore keyStore) { lock (this.DisposeLock) { if (this.IsDisposed) { throw OperationException.WrapException(this.DisposeReason); } lock (_securitySessions) { SecuritySession iSecuritySession = _securitySessions[securitySessionName] as SecuritySession; if (iSecuritySession == null) { IKeyProvider iKeyProvider = keyStore.GetKey(securitySessionName); if (iKeyProvider == null) { throw GenuineExceptions.Get_Security_ContextNotFound(securitySessionName); } iSecuritySession = iKeyProvider.CreateSecuritySession(securitySessionName, this); _securitySessions[securitySessionName] = iSecuritySession; } return(iSecuritySession); } } }
protected override void OnCreate(Bundle bundle) { IoCManager.RegisterType <IImageDimension, AndroidImageDimensions>(); TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; SetTheme(Resource.Style.MainTheme); base.OnCreate(bundle); // Init Navigation NavigationService.Instance.RegisterViewModels(typeof(MainPage).Assembly); IoCManager.RegisterInstance(typeof(INavigationService), NavigationService.Instance); IoCManager.RegisterInstance(typeof(IViewCreator), NavigationService.Instance); // init other inversion of control classes IoCManager.RegisterInstance(typeof(IFabSizeCalculator), new AndroidFabSizeCalculator()); IoCManager.RegisterInstance(typeof(IAudioPlayer), new DroidAudioPlayer()); IoCManager.RegisterInstance(typeof(IStatusBarController), new DroidStatusBarController()); IoCManager.RegisterInstance(typeof(ILocationManager), new LocationManager()); IoCManager.RegisterInstance(typeof(IKeyProvider), new AndroidKeyProvider()); IoCManager.RegisterInstance(typeof(IBarsColorsChanger), new DroidBarsColorsChanger(this)); // setup crash reporting IKeyProvider keyProvider = IoCManager.Resolve <IKeyProvider>(); CrashManager.Register(this, keyProvider.GetKeyByName("hockeyapp.android")); // init forms and third party libraries CachedImageRenderer.Init(); Xamarin.Forms.Forms.Init(this, bundle); Xamarin.FormsMaps.Init(this, bundle); LoadApplication(new App()); }
public KeysController(ObservableCollection <Message> keys, IMessageProvider messageProvider, IKeyProvider keyProvider, IConcurrencyService concurrencyService) { this.keys = keys; this.messageProvider = messageProvider; this.keyProvider = keyProvider; this.concurrencyService = concurrencyService; }
/// <summary> /// Register a key provider which can be querried for keys. /// </summary> /// <param name="provider">The provider to register.</param> public void RegisterProvider(IKeyProvider provider) { if (provider != null) { keyProvider.Add(provider); } }
/// <summary> /// Associates the provided key provider with the specified Security Session name. /// Removes the record if iKeyProvider is a null reference. /// </summary> /// <param name="name">The name of Security Context.</param> /// <param name="iKeyProvider">The key provider or a null reference.</param> public static void SetGlobalKey(string name, IKeyProvider iKeyProvider) { BinaryLogWriter binaryLogWriter = GenuineLoggingServices.BinaryLogWriter; if (iKeyProvider == null) { // LOG: if (binaryLogWriter != null && binaryLogWriter[LogCategory.Security] > 0) { binaryLogWriter.WriteEvent(LogCategory.Security, "SecuritySessionServices.SetGlobalKey", LogMessageType.KeyProviderDissociated, null, null, null, null, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, null, null, -1, 0, 0, 0, iKeyProvider.ToString(), name, null, null, "The Key Provider (\"{0}\") has been dissociated from the \"{1}\" name.", iKeyProvider.ToString(), name); } _globalKeys.Remove(name); } else { if (binaryLogWriter != null && binaryLogWriter[LogCategory.Security] > 0) { binaryLogWriter.WriteEvent(LogCategory.Security, "SecuritySessionServices.SetGlobalKey", LogMessageType.KeyProviderAssociated, null, null, null, null, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, null, null, -1, 0, 0, 0, iKeyProvider.ToString(), name, null, null, "The Key Provider (\"{0}\") has been associated with the \"{1}\" name.", iKeyProvider.ToString(), name); } _globalKeys[name] = iKeyProvider; } }
/// <summary> /// Associates the provided key provider with the specified Security Session name. /// Removes the record if iKeyProvider is a null reference. /// </summary> /// <param name="name">The name of Security Context.</param> /// <param name="iKeyProvider">The key provider or a null reference.</param> public void SetKey(string name, IKeyProvider iKeyProvider) { BinaryLogWriter binaryLogWriter = GenuineLoggingServices.BinaryLogWriter; if (iKeyProvider == null) { // LOG: if (binaryLogWriter != null && binaryLogWriter[LogCategory.Security] > 0 ) binaryLogWriter.WriteEvent(LogCategory.Security, "KeyStore.SetKey", LogMessageType.KeyProviderDissociated, null, null, null, null, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, null, name, -1, 0, 0, 0, iKeyProvider.ToString(), name, null, null, "The Key Provider (\"{0}\") has been dissociated from the \"{1}\" name.", iKeyProvider.ToString(), name); this._keys.Remove(name); } else { // LOG: if (binaryLogWriter != null && binaryLogWriter[LogCategory.Security] > 0 ) binaryLogWriter.WriteEvent(LogCategory.Security, "SecuritySessionServices.SetGlobalKey", LogMessageType.KeyProviderAssociated, null, null, null, null, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, null, name, -1, 0, 0, 0, iKeyProvider.ToString(), name, null, null, "The Key Provider (\"{0}\") has been associated with the \"{1}\" name.", iKeyProvider.ToString(), name); this._keys[name] = iKeyProvider; } }
/// <summary> /// Creates a new instance. /// </summary> /// <param name="keyProvider">Required. A function to return the value of the entity's primary key.</param> /// <param name="keyBinder">The binder for the entity id.</param> /// <param name="items">Required. The list of entities to pre-populate the current instance with.</param> public InMemoryRepository( IKeyProvider <TEntity, TKey> keyProvider, IKeyBinder <TEntity, TKey> keyBinder, IEnumerable <TEntity> items) : this(keyProvider, keyBinder, items, ObjectMapperManager.DefaultInstance) { }
/// <summary>Configure the signature behavior for a specific <paramref name="issuer"/>.</summary> public TokenValidationPolicyBuilder RequireSignatureByDefault(string issuer, IKeyProvider keyProvider, SignatureAlgorithm defaultAlgorithm) { if (issuer is null) { throw new ArgumentNullException(nameof(issuer)); } if (keyProvider is null) { throw new ArgumentNullException(nameof(keyProvider)); } if (defaultAlgorithm is null) { throw new ArgumentNullException(nameof(defaultAlgorithm)); } if (defaultAlgorithm == SignatureAlgorithm.None) { throw new ArgumentException($"The algorithm 'none' is not valid with the method {nameof(RequireSignature)}. Use the method {nameof(AcceptUnsecureToken)} instead.", nameof(defaultAlgorithm)); } _hasSignatureValidation = true; var policy = SignatureValidationPolicy.Create(keyProvider, defaultAlgorithm); _signaturePolicies[issuer] = policy; return(this); }
public override async Task Invoke(AspectContext context, AspectDelegate next) { ICacher cacher = context.ServiceProvider.GetService(typeof(ICacher)) as ICacher; IKeyProvider keyProvider = context.ServiceProvider.GetService(typeof(IKeyProvider)) as IKeyProvider; IHttpContextAccessor httpContextAccessor = context.ServiceProvider.GetService(typeof(IHttpContextAccessor)) as IHttpContextAccessor; var key = keyProvider.ProvideKey(this.KeyType, context.Parameters, httpContextAccessor, this.InParamKey); var fullKey = $"xLiAd_Limiter:{context.Implementation.GetType().FullName}_{context.ImplementationMethod.Name}:{key}"; ILimitPolicyProvider limitPolicyProvider = context.ServiceProvider.GetService(typeof(ILimitPolicyProvider)) as ILimitPolicyProvider; var policies = limitPolicyProvider.ParsePolicy(this.LimitPolicieString); foreach (var policy in policies) { var rk = $"{fullKey}:{policy.Key}"; var list = cacher.Get <List <DateTime> >(rk); int n = list?.Count(x => (DateTime.Now - x).TotalSeconds < policy.Key) ?? 0; if (n >= policy.Value) { throw new OperationLimitException("此操作超过次数限制!"); } else { var lr = list ?? new List <DateTime>(); lr.Add(DateTime.Now); cacher.Set(rk, lr, TimeSpan.FromSeconds(policy.Key)); } } await next(context); }
public InMemoryRepository( IKeyProvider <TEntity, Guid> keyProvider, IKeyBinder <TEntity, Guid> keyBinder, IEnumerable <TEntity> items) : base(keyProvider, keyBinder, items) { }
/// <summary> /// Constrocutor for the abstract class. This is to guarantee that all implementations have a secret key /// </summary> /// <param name="secretKey"></param> /// <param name="mode">The hash mode to use</param> public Otp(IKeyProvider secretKey, OtpHashMode mode) { if (!(secretKey != null)) throw new ArgumentNullException("secretKey"); this.secretKey = secretKey; this.hashMode = mode; }
/// <summary> /// Initialized new instance of RefreshKey /// </summary> /// <param name="keyUri"></param> /// <param name="keyProvider"></param> public RefreshKey(Uri keyUri, IKeyProvider keyProvider) { Guard.ArgumentIsNotNull(nameof(keyUri), keyUri); Guard.ArgumentIsNotNull(nameof(keyProvider), keyProvider); _keyUri = keyUri; _keyProvider = keyProvider; }
/// <summary> /// Uses the procedure defined in RFC 4226 section 7.5 to derive a key from the master key /// </summary> /// <param name="masterKey">The master key from which to derive a device specific key</param> /// <param name="publicIdentifier">The public identifier that is unique to the authenticating device</param> /// <param name="mode">The hash mode to use. This will determine the resulting key lenght. The default is sha-1 (as per the RFC) which is 20 bytes</param> /// <returns>Derived key</returns> public static byte[] DeriveKeyFromMaster(IKeyProvider masterKey, byte[] publicIdentifier, OtpHashMode mode = OtpHashMode.Sha1) { if (masterKey == null) { throw new ArgumentNullException("masterKey"); } return(masterKey.ComputeHmac(mode, publicIdentifier)); }
public I18N( IOptions <JsonLocalizationOptions> options, IKeyProvider keyProvider ) { _options = options?.Value ?? throw new ArgumentNullException(nameof(options)); _keyProvider = keyProvider ?? throw new ArgumentNullException(nameof(keyProvider)); }
public EntityComparer( string entityName, IKeyProvider <Entity> keyProvider, ISkipAttributeCriteria skipAttributeCriteria = null, bool onlyActiveRecords = false) : this(entityName, keyProvider, GetDefaultFilter(onlyActiveRecords), skipAttributeCriteria) { this.OnlyActiveRecords = onlyActiveRecords; }
/// <summary> /// Creates a package reader configured to read from a provided stream (containing the package). /// </summary> /// <remarks> /// Immediately reads package manifest header and manifest. /// </remarks> /// <param name="stream">Stream to read the package from.</param> /// <param name="keyProvider">Service that supplies possible cryptographic keys.</param> /// <param name="closeOnDispose"> /// If <c>true</c>, <paramref name="stream" /> will be closed when the reader is disposed. /// </param> internal PackageReader(Stream stream, IKeyProvider keyProvider, bool closeOnDispose = false) { _readingStream = stream; _closeOnDispose = closeOnDispose; ManifestCryptographyScheme mCryptoScheme; _manifestHeader = ReadManifestHeader(_readingStream, out mCryptoScheme, out _manifestCryptoConfig); _manifest = ReadManifest(keyProvider, mCryptoScheme); }
public void Init() { Mock <IKeyProvider> moqKey = new Mock <IKeyProvider>(); moqKey.Setup(o => o.IV).Returns("88888888"); moqKey.Setup(o => o.Key).Returns("77777777"); KeyProvider = moqKey.Object; }
public AsymmetricKeyProvider(OidToCipherTypeMapper cipherTypeMapper, KeyInfoWrapper keyInfoWrapper, IKeyProvider <RsaKey> rsaKeyProvider, IKeyProvider <DsaKey> dsaKeyProvider, IEcKeyProvider ecKeyProvider, IElGamalKeyProvider elGamalKeyProvider) { this.cipherTypeMapper = cipherTypeMapper; this.rsaKeyProvider = rsaKeyProvider; this.dsaKeyProvider = dsaKeyProvider; this.ecKeyProvider = ecKeyProvider; this.elGamalKeyProvider = elGamalKeyProvider; this.keyInfoWrapper = keyInfoWrapper; }
static IEnumerable <KeyPress> ToEnumerable(IKeyProvider provider, KeyPlayer player) { var keys = new List <KeyPress>(); provider.GetKeyStream().Subscribe(keys.Add); player.Play(); return(keys); }
public KeyboardInputChannel(IKeyProvider keyProvider, IKeySettings settings) { this.provider = keyProvider; this.settings = settings; this.state = new ControllerState(); //this.provider.KeyDown += Provider_KeyDown; //this.provider.KeyUp += Provider_KeyUp; }
/// <summary> /// Constrocutor for the abstract class. This is to guarantee that all implementations have a secret key /// </summary> /// <param name="secretKey"></param> /// <param name="mode">The hash mode to use</param> public Otp(IKeyProvider secretKey, OtpHashMode mode) { if (!(secretKey != null)) { throw new ArgumentNullException("secretKey"); } this.secretKey = secretKey; this.hashMode = mode; }
/// <summary> /// Create a TOTP instance /// </summary> /// <param name="secretKey">The secret key to use in TOTP calculations</param> /// <param name="step">The time window step amount to use in calculating time windows. The default is 30 as recommended in the RFC</param> /// <param name="mode">The hash mode to use</param> /// <param name="totpSize">The number of digits that the returning TOTP should have. The default is 6.</param> /// <param name="timeCorrection">If required, a time correction can be specified to compensate of an out of sync local clock</param> public Totp(IKeyProvider secretKey, int step = 30, OtpHashMode mode = OtpHashMode.Sha1, int totpSize = 6, TimeCorrection timeCorrection = null) : base(secretKey, mode) { VerifyParameters(step, totpSize); _step = step; _totpSize = totpSize; // we never null check the corrected time object. Since it's readonly, we'll ensure that it isn't null here and provide neatral functionality in this case. _correctedTime = timeCorrection ?? TimeCorrection.UncorrectedInstance; }
public Context(TIn sourceObject, IKeyProvider <TIn> keyProvider) { SourceObject = sourceObject; SuccessorNodesStack = new Stack <ILink <TIn> >(); ExecutedNodesStack = new Stack <ILink <TIn> >(); _results = new Dictionary <string, FuncResult>(); _globalResult = new Dictionary <string, object>(); KeyProvider = keyProvider ?? new DefaultKeyProvider <TIn>(); _executionInfo = new List <LinkExecutionInfo <TIn> >(); }
public JwtFactory(ITimeProvider timeProvider, IIdentityGenerator <Guid> identityGenerator, ITokenExpirationProvider tokenExpirationProvider, IKeyProvider keyProvider) { _timeProvider = timeProvider; _identityGenerator = identityGenerator; _tokenExpirationProvider = tokenExpirationProvider; _keyProvider = keyProvider; }
/// <summary> /// Creates a package reader configured to read from a file. /// </summary> /// <param name="filePath">Path of the file containing a package.</param> /// <param name="keyProvider">Service that supplies possible cryptographic keys.</param> /// <returns>Package ready for reading.</returns> /// <exception cref="ArgumentException">File does not exist at the path specified.</exception> public static PackageReader FromFile(string filePath, IKeyProvider keyProvider) { var file = new FileInfo(filePath); if (file.Exists == false) { throw new ArgumentException(); } return(FromStream(file.OpenRead(), keyProvider)); }
/// <summary> /// Create a TOTP instance /// </summary> /// <param name="secretKey">The secret key to use in TOTP calculations</param> /// <param name="step">The time window step amount to use in calculating time windows. The default is 30 as recommended in the RFC</param> /// <param name="mode">The hash mode to use</param> /// <param name="totpSize">The number of digits that the returning TOTP should have. The default is 6.</param> /// <param name="timeCorrection">If required, a time correction can be specified to compensate of an out of sync local clock</param> public Totp(IKeyProvider secretKey, int step = 30, OtpHashMode mode = OtpHashMode.Sha1, int totpSize = 6, TimeCorrection timeCorrection = null) : base(secretKey, mode) { VerifyParameters(step, totpSize); this.step = step; this.totpSize = totpSize; // we never null check the corrected time object. Since it's readonly, we'll ensure that it isn't null here and provide neatral functionality in this case. this.correctedTime = timeCorrection ?? TimeCorrection.UncorrectedInstance; }
public FileCabinetStreamProvider(IFileCabinet fileCabinet, IUploadValidator fileValidator, IKeyProvider keyProvider, string tempFileFolder) : base(tempFileFolder) { Contract.NotNull(fileCabinet, nameof(fileCabinet)); Contract.NotNull(fileValidator, nameof(fileValidator)); Contract.NotNull(keyProvider, nameof(keyProvider)); Contract.NotNullOrEmpty(tempFileFolder, nameof(tempFileFolder)); this.fileCabinet = fileCabinet; this.fileValidator = fileValidator; this.keyProvider = keyProvider; }
/// <summary> /// Constructor for the abstract class using a generic key provider /// </summary> /// <param name="key"></param> /// <param name="mode">The hash mode to use</param> public Otp(IKeyProvider key, OtpHashMode mode) { if (key == null) { throw new ArgumentNullException("key"); } this.secretKey = key; this.hashMode = mode; }
protected override void OnCreate(Bundle bundle) { var dataAccess = IoCManager.Resolve <IDataAccess>(); if (Settings.ShouldDeleteDbOnLaunch) { File.Delete(dataAccess.DatabasePath); Settings.ShouldDeleteDbOnLaunch = false; } dataAccess.CreateDatabase(0); // ensures the database exists and is up to date IoCManager.RegisterType <IImageDimension, AndroidImageDimensions>(); IoCManager.RegisterType <IAppCloser, AndroidAppCloser>(); TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; SetTheme(Resource.Style.MainTheme); Window.SetStatusBarColor(Android.Graphics.Color.Black); base.OnCreate(bundle); // Init Navigation NavigationService.Instance.RegisterViewModels(typeof(MainPage).Assembly); IoCManager.RegisterInstance(typeof(INavigationService), NavigationService.Instance); IoCManager.RegisterInstance(typeof(IViewCreator), NavigationService.Instance); // init other inversion of control classes IoCManager.RegisterInstance(typeof(IFabSizeCalculator), new AndroidFabSizeCalculator()); IoCManager.RegisterType <IAudioPlayer, DroidAudioPlayer>(); IoCManager.RegisterInstance(typeof(INotificationPlayer), new DroidNotificationPlayer()); IoCManager.RegisterInstance(typeof(ILocationManager), new LocationManager()); IoCManager.RegisterInstance(typeof(IKeyProvider), new AndroidKeyProvider()); IoCManager.RegisterInstance(typeof(IBarsColorsChanger), new DroidBarsColorsChanger(this)); IoCManager.RegisterInstance(typeof(IDbChangedHandler), new DbChangedHandler()); IoCManager.RegisterInstance(typeof(INetworkAccessChecker), new DroidNetworkAccessChecker()); IoCManager.RegisterInstance(typeof(IStorageSizeProvider), new DroidStorageSizeProvider()); // setup crash reporting IKeyProvider keyProvider = IoCManager.Resolve <IKeyProvider>(); CrashManager.Register(this, keyProvider.GetKeyByName("hockeyapp.android")); // init forms and third party libraries CachedImageRenderer.Init(enableFastRenderer: true); Forms.Init(this, bundle); SvgImageViewRenderer.Init(); CarouselViewRenderer.Init(); UserDialogs.Init(() => (Activity)Forms.Context); DesignMode.IsEnabled = false; LoadApplication(new App()); }
/// <summary> /// Constructor for the abstract class. This is to guarantee that all implementations have a secret key /// </summary> /// <param name="secretKey"></param> /// <param name="mode">The hash mode to use</param> public Otp(byte[] secretKey, OtpHashMode mode) { if (!(secretKey != null)) throw new ArgumentNullException("secretKey"); if (!(secretKey.Length > 0)) throw new ArgumentException("secretKey empty"); // when passing a key into the constructor the caller may depend on the reference to the key remaining intact. this.secretKey = new InMemoryKey(secretKey); this.hashMode = mode; }
public SqlDataLayerGenerator(IMapper mapperService,ITableProvider tableProvider, IKeyProvider keyProvider, IViewProvider viewProvider, IStoredProcedureProvider storedProcedureProvider, IParameterProvider parameterProvider, IEntityGenerator entityGenerator, IProviderGenerator providerGenerator,INinjectModuleGenerator ninjectModuleGenerator,[Named("settings")]IParameterReaderService parameterReaderService) { _mapper = mapperService; _tableProvider = tableProvider; _keyProvider = keyProvider; _viewProvider = viewProvider; _storedProcedureProvider = storedProcedureProvider; _parameterProvider = parameterProvider; _entityGenerator = entityGenerator; _providerGenerator = providerGenerator; _ninjectModuleGenerator = ninjectModuleGenerator; _parameterReaderService = parameterReaderService; }
public CryptoService(IKeyProvider keyProvider) { _keyProvider = keyProvider; }
public CryptoService(IKeyProvider provider) { System.Diagnostics.Contracts.Contract.Requires<ArgumentNullException>(provider != null); _provider = provider; }
public BrowseController(IFileCabinet fileCabinet, IKeyProvider keyProvider) { this.fileCabinet = fileCabinet; this.keyProvider = keyProvider; }
/// <summary> /// Create an HOTP instance /// </summary> /// <param name="secretKey">The secret key to use in HOTP calculations</param> /// <param name="mode">The hash mode to use</param> public Hotp(IKeyProvider secretKey, OtpHashMode mode = OtpHashMode.Sha1) : base(secretKey, mode) { }
public AesHttpContentEncryptor(IKeyProvider keyProvider) { this.keyProvider = keyProvider; this.algorithm = new AesManaged(); }
/// <summary> /// Uses the procedure defined in RFC 4226 section 7.5 to derive a key from the master key /// </summary> /// <param name="masterKey">The master key from which to derive a device specific key</param> /// <param name="serialNumber">A serial number that is unique to the authenticating device</param> /// <param name="mode">The hash mode to use. This will determine the resulting key lenght. The default is sha-1 (as per the RFC) which is 20 bytes</param> /// <returns>Derived key</returns> public static byte[] DeriveKeyFromMaster(IKeyProvider masterKey, int serialNumber, OtpHashMode mode = OtpHashMode.Sha1) { return DeriveKeyFromMaster(masterKey, KeyUtilities.GetBigEndianBytes(serialNumber), mode); }
/// <summary> /// Uses the procedure defined in RFC 4226 section 7.5 to derive a key from the master key /// </summary> /// <param name="masterKey">The master key from which to derive a device specific key</param> /// <param name="publicIdentifier">The public identifier that is unique to the authenticating device</param> /// <param name="mode">The hash mode to use. This will determine the resulting key lenght. The default is sha-1 (as per the RFC) which is 20 bytes</param> /// <returns>Derived key</returns> public static byte[] DeriveKeyFromMaster(IKeyProvider masterKey, byte[] publicIdentifier, OtpHashMode mode = OtpHashMode.Sha1) { if (masterKey == null) throw new ArgumentNullException("masterKey"); return masterKey.ComputeHmac(mode, publicIdentifier); }