Authenticator – integrarlo in VbNet

Generazione chiave segreta

Function GeneraChiaveSegreta() As String
    Dim chiaveBytes(19) As Byte ' 20 byte per una chiave di base32 di 80 bit
    Using rng As New RNGCryptoServiceProvider()
        rng.GetBytes(chiaveBytes)
    End Using

    Dim input As Byte() = chiaveBytes
    Dim base32Chars As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"

    Dim bits As Integer = 0
    Dim buffer As Integer = 0
    Dim output As New StringBuilder()

    For Each b As Byte In input
        buffer = (buffer << 8) Or b
        bits += 8
        While bits >= 5
            output.Append(base32Chars(buffer >> (bits - 5)))
            buffer = buffer And ((1 << (bits - 5)) - 1)
            bits -= 5
        End While
    Next

    If bits > 0 Then
        buffer = buffer << (5 - bits)
        output.Append(base32Chars(buffer))
    End If

    Return output.ToString()
End Function

Una volta creata la chiave segreta genero il QrCode

picQrcode.Image = GeneraQRCode("otpauth://Nome Programma: " & Application.Session("utente") & "?secret=" & chiavesegreta)

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

eprime
Author: eprime

Torna in alto