Yubico Forum

...visit our web-store at store.yubico.com
It is currently Tue Jan 30, 2018 3:07 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: decoding help
PostPosted: Thu Mar 05, 2009 1:22 pm 
Offline

Joined: Thu May 29, 2008 9:44 am
Posts: 21
Hi,

I am implimenting a server side parser in dot net and having a spot of bother. I have:

1: reset the otp on a yubikey. the aes key I used was: 265670755823513b6d54423c79536560
2: generated a string. with the key's prefix removed this has produced the following strings (format yubiHex - realHex)

cnkkndvrckucleuvinfiihnvhllvkgnl - 0b99b2fc09e0a3ef7b4776bf6aaf95ba
vkuviitdinjvutcvcjjkhenuiteudvbg - f9ef77d27b8fed0f088963be7d3e2f15
jtcbldtujkdjfugnubuuhvbgijdgnvgv - 8d01a2de89284e5be1ee6f157825bf5f

3: now, the next step, as i understand it, is to decode the real hex. however when i try to aes-decrypt f9ef77d27b8fed0f088963be7d3e2f15 with the key 265670755823513b6d54423c79536560 i get "PKCS7 padding is invalid and cannot be removed".

i suspect i am trying to do the wrong thing but I'm not 100% sure i am using the aes decryption correctly either so any pointers would be much appreciated.

Thanks


Top
 Profile  
Reply with quote  

Share On:

Share on Facebook FacebookShare on Twitter TwitterShare on Tumblr TumblrShare on Google+ Google+

 Post subject: Re: decoding help
PostPosted: Thu Mar 05, 2009 2:29 pm 
Offline
Yubico Team
Yubico Team

Joined: Wed Oct 01, 2008 8:11 am
Posts: 210
It seems to be a dot net specific issue. We believe this error is related to the size of the data stream.

We would appreciate if you can provide us the sample code. This will help us determining the exact cause of the problem you are facing.


Top
 Profile  
Reply with quote  
 Post subject: Re: decoding help
PostPosted: Thu Mar 05, 2009 2:56 pm 
Offline

Joined: Thu May 29, 2008 9:44 am
Posts: 21
This is dot net 1.1
Also get the same error in VS2005

Code:

    Private Sub btDecrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btDecrypt.Click
        Dim crypto As New System.Security.Cryptography.RijndaelManaged
        Dim encryptedData As Byte() = FromHex("f9ef77d27b8fed0f088963be7d3e2f15")
        crypto.Key = FromHex("265670755823513b6d54423c79536560")
        crypto.IV = New Byte(encryptedData.Length - 1) {}

        Dim encryptedMemStream As New System.IO.MemoryStream(encryptedData, 0, encryptedData.Length)
        Dim b() As Byte = New Byte(encryptedData.Length - 1) {}

        Dim cs As New System.Security.Cryptography.CryptoStream(encryptedMemStream, crypto.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Read)

        Try
            cs.Read(b, 0, encryptedData.Length - 1)
        Catch ex As System.Security.Cryptography.CryptographicException
            Throw New System.Security.Cryptography.CryptographicException("Unable to decrypt data. The provided key may be invalid.", ex)
        Finally
            cs.Close()
        End Try
        tbEncryptResult.Text = ToHex(b)
    End Sub

    Shared Function ToHex(ByVal ba() As Byte) As String
        If ba Is Nothing OrElse ba.Length = 0 Then
            Return ""
        End If
        Const HexFormat As String = "{0:X2}"
        Dim sb As New System.Text.StringBuilder
        For Each b As Byte In ba
            sb.Append(String.Format(HexFormat, b))
        Next
        Return sb.ToString
    End Function

    Shared Function FromHex(ByVal hexEncoded As String) As Byte()
        If hexEncoded Is Nothing OrElse hexEncoded.Length = 0 Then
            Return Nothing
        End If
        Try
            Dim l As Integer = Convert.ToInt32(hexEncoded.Length / 2)
            Dim b(l - 1) As Byte
            For i As Integer = 0 To l - 1
                b(i) = Convert.ToByte(hexEncoded.Substring(i * 2, 2), 16)
            Next
            Return b
        Catch ex As Exception
            Throw New System.FormatException("The provided string does not appear to be Hex encoded:" & _
                Environment.NewLine & hexEncoded & Environment.NewLine, ex)
        End Try
    End Function



Are we sure that this is indeed a valid key / encrypted pair?


Top
 Profile  
Reply with quote  
 Post subject: Re: decoding help
PostPosted: Thu Mar 05, 2009 3:50 pm 
Offline

Joined: Thu May 29, 2008 9:44 am
Posts: 21
Think I have it. Added

Code:
        crypto.Padding = System.Security.Cryptography.PaddingMode.None


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group