/// <summary> /// Encrypts finger data captured for best finger detection. /// </summary> /// <param name="data">The data to encrypt.</param> /// <param name="key">The key to encrypt data.</param> /// <exception cref="ArgumentNullException"><paramref name="data"/> or <paramref name="key"/> is null.</exception> public void Encrypt(BestFingerInfo data, SessionKey key) { ValidateNull(data, nameof(data)); ValidateNull(key, nameof(key)); // Create Rbd bytes. var rbdBytes = data.ToXml("Rbd").ToString(SaveOptions.DisableFormatting).GetBytes(); using (var sha = SHA256.Create()) { var rbdHash = sha.ComputeHash(rbdBytes); // Encrypt data. var encryptedRbd = key.Encrypt(rbdBytes); var encryptedHash = key.Encrypt(rbdHash); KeyInfo = key.KeyInfo; // Set related properties. AadhaarNumber = data.AadhaarNumber; Timestamp = data.Timestamp; Data = new EncryptedData { Data = Convert.ToBase64String(encryptedRbd) }; Hmac = Convert.ToBase64String(encryptedHash); if (DeviceInfo != null) { DeviceInfo.IrisDeviceCode = DeviceInfo.DeviceNotApplicable; } } Array.Clear(rbdBytes, 0, rbdBytes.Length); }
public static async Task BestFingerDetectionAsync() { #region Device Level // Set Best Finger Info var bestFingerInfo = new BestFingerInfo { AadhaarNumber = "999999990019" }; bestFingerInfo.Fingers.Add(new TestFinger { Quality = Nfiq.Excellent, NumberOfAttempts = 3, Position = BiometricPosition.LeftIndex, Data = BiometricData }); bestFingerInfo.Fingers.Add(new TestFinger { Quality = Nfiq.Excellent, NumberOfAttempts = 4, Position = BiometricPosition.LeftMiddle, Data = BiometricData }); bestFingerInfo.Fingers.Add(new TestFinger { Quality = Nfiq.Excellent, NumberOfAttempts = 5, Position = BiometricPosition.LeftRing, Data = BiometricData }); // Set Device Info var bfdContext = new BfdContext { DeviceInfo = Configuration.Current.DeviceInfo.Create() }; // Encrypt Data var sessionKey = new SessionKey(Configuration.Current.UidaiEncryption, false); await bfdContext.EncryptAsync(bestFingerInfo, sessionKey); #endregion #region Device To Agency // TODO: Wrap DeviceContext{T} into AUA specific protocol and send it to AUA. // On Device Side: // var deviceXml = deviceContext.ToXml(); // var wrapped = WrapIntoAuaProtocol(deviceXml); // On Agency Side: // var auaXml = UnwrapFromAuaProtocol(wrapped); // var auaContext = new BfdContext(); // auaContext.FromXml(auaXml); #endregion #region Agency Level // Perform Best Finger Detection var bfdClient = new BfdClient { AgencyInfo = Configuration.Current.AgencyInfo, Request = new BfdRequest(bfdContext) { Signer = XmlSignature }, Response = new BfdResponse { Verifier = XmlSignature } }; await bfdClient.GetResponseAsync(); Console.WriteLine(string.IsNullOrEmpty(bfdClient.Response.ErrorCode) ? $"Best Finger Is: {bfdClient.Response.Ranks.First().Value}" : $"Error Code: {bfdClient.Response.ErrorCode}"); #endregion #region Agency To Device // TODO: Wrap BfdResponse into AUA specific protocol and send it to device. #endregion }
/// <summary> /// Asynchronously encrypts data captured for request. /// </summary> /// <param name="data">The data to encrypt.</param> /// <param name="key">The key to encrypt data.</param> /// <returns>A task that represents the asynchronous encrypt operation.</returns> public async Task EncryptAsync(BestFingerInfo data, SessionKey key) => await Task.Run(() => Encrypt(data, key));