Yubico Forum https://forum.yubico.com/ |
|
decoding help https://forum.yubico.com/viewtopic.php?f=5&t=281 |
Page 1 of 1 |
Author: | metamind [ Thu Mar 05, 2009 1:22 pm ] |
Post subject: | decoding help |
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 |
Author: | network-marvels [ Thu Mar 05, 2009 2:29 pm ] |
Post subject: | Re: decoding help |
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. |
Author: | metamind [ Thu Mar 05, 2009 2:56 pm ] |
Post subject: | Re: decoding help |
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? |
Author: | metamind [ Thu Mar 05, 2009 3:50 pm ] |
Post subject: | Re: decoding help |
Think I have it. Added Code: crypto.Padding = System.Security.Cryptography.PaddingMode.None
|
Page 1 of 1 | All times are UTC + 1 hour |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |