daviddesmet / paseto-dotnet

🔑 Paseto.NET, a Paseto (Platform-Agnostic Security Tokens) implementation for .NET
MIT License
96 stars 8 forks source link

Unable to build token #13

Closed jyloo closed 5 years ago

jyloo commented 5 years ago

I'm getting System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1. is there some special requirements for the private key? i'm guessing this has something to do with my private key

Dim sc As Byte() = Nothing
        Using fs As New StreamReader(Server.MapPath("/secret.txt"))
            fs.Read()
            Dim x = fs.ReadToEnd()
            sc = Encoding.UTF8.GetBytes(x) 'GetPem("RSA PRIVATE KEY", Encoding.Default.GetBytes(x))
        End Using

        Dim token = New PasetoBuilder(Of Version1)().
            WithKey(sc).
            AddClaim("example", "Hello Paseto!").
            Expiration(DateTime.UtcNow.AddHours(24)).
            AsPublic().
            Build()
        lt.Text = token
daviddesmet commented 5 years ago

How are your creating the private key? This test shows how the private key is created and consumed. Perhaps it could be of help?

jyloo commented 5 years ago

@idaviddesmet thanks for your kind guidance. Guess I'm doing it wrongly for the secret key previously. Now everything works!