/// <summary> Encrypted seed (random number) created inside ILOCKIT and passd to app.</summary>
privatebyte[]SeedLockEncrypted{get;}
/// <summary> Contstructs a auth crypto helper object.</summary>
/// <param name="seedLockEncrypted">Encrypted seed to deocode using <see cref="KeyCopri"/>.</param>
/// <param name="keyCopri">Key used to to decrypt <see cref="SeedLockEncrypted"/>.</param>
publicAuthCryptoHelper(
byte[]seedLockEncrypted,
byte[]keyCopri,
ICiphercipher)
{
KeyCopri=keyCopri;
SeedLockEncrypted=seedLockEncrypted;
Cipher=cipher??newCipher();
}
/// <summary> Public for testing purposes only.</summary>
publicbyte[]GetSeedLock()
{
byte[]seedLockDecrypted;
varseedLockEncrypted=SeedLockEncrypted;
varkeyCopri=KeyCopri;
try
{
seedLockDecrypted=Cipher.Decrypt(
keyCopri,
seedLockEncrypted);
}
catch(System.Exceptionexception)
{
Log.ForContext<AuthCryptoHelper>().Error("Decrypting seed from lock failed. {Exception}",exception);
throw;
}
Log.ForContext<AuthCryptoHelper>().Verbose($"Lock random number decrypted from {string.Join(",", seedLockEncrypted)} to {string.Join(",", seedLockDecrypted)} using {string.Join(",", keyCopri)}.");
returnseedLockDecrypted;
}
publicbyte[]GetAccessKeyEncrypted()
{
varaccessKey=GetSeedLock();
if(accessKey==null||accessKey.Length<=0)
{
Log.ForContext<AuthCryptoHelper>().Error("Creating access key failed, Key must not be null or empty.");
Log.ForContext<AuthCryptoHelper>().Verbose($"Access key encrypted from {string.Join(",", accessKey)} to {string.Join(",", acccessKeyEncrypted)} using {string.Join(",", keyCopri)}.");