Imports System.Configuration
Imports Strata.Configuration.Client.Models.Jazz

Namespace Encryptors

    Public Class UberEncryptionMethod
        Implements IPasswordEncryptionMethod

        Public Sub New()

        End Sub

#Region " Methods "

        Public Shared Function GetUberMonet(ByVal anOrgPin As String) As String
            Return GetUberMonet(Date.Today, anOrgPin, ConfigurationManager.AppSettings(NameOf(StrataJazzOptions.UberMonetKey)))
        End Function

        Private Shared Function GetUberMonet(ByVal aDate As Date, ByVal anOrgPIN As String, ByVal aKey As String) As String
            Dim ha As New EncryptionUtils.Hasher(EncryptionUtils.Hasher.Provider.SHA256)

            Dim lsHashBefore As String
            Dim lsResult As String

            lsHashBefore = Format(aDate, "dd-MM-yyyy") & "-" & anOrgPIN & "-" & aKey

            Dim d As New EncryptionUtils.Data(lsHashBefore)

            Dim dResult As EncryptionUtils.Data = ha.Calculate(d)
            lsResult = Left(dResult.Hex, 6)

            ha = Nothing

            Return lsResult
        End Function

#End Region

#Region " IPasswordEncryptionMethod "

        Public Function Encode(ByVal username As String, ByVal anOrgPin As String, ByVal aNewPassword As String, ByVal aUserGUID As System.Guid, aSalt As String) As String Implements IPasswordEncryptionMethod.Encode
            Return GetUberMonet(anOrgPin)
        End Function

#End Region

    End Class

End Namespace