Salut merci ToOnS mais je n'ai pas encore arrivé :(
voila :
RSA :
Cliquez pour révéler
Cliquez pour masquer
Public Class OunasRSA
Private Const Key As String =
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApHRiGIhIJrNdUJkKGtWC" +
"sSqIza+2gPsjGXhSoDTOcokq59Et8d8SzgF68RvAZXezPO8tnUhlyvaDem4QSFLV" +
"PVAmSRcp47HW4lpp11WHBlDsEEXQTBkM8nDyqSgn8dMANvButRDt/44OKslrfqmV" +
"7ANmZggZ2wXN0T6XWt3FVC66X8+E7rUMUOREQYCDq3zrX4dNYy3y21lyJZeXTkSd" +
"AmijqIHrrwLPTA/wpWLCEaIJ9OAWjds8L6TqONXvnf3qOtI/QsrWv24lRjtmRSeR" +
"eKFIPrk8QQbcd2h4VUi06fJZ2ydCx0pOwU33izN42pmZoCrgdCwghFm1i2feQa0M" +
"vQIDAQAB"
Private Shared Function CompareByteArrays(ByVal a As Byte(), ByVal b As Byte()) As Boolean
If a.Length <> b.Length Then
Return False
End If
Dim i As Integer = 0
For Each c As Byte In a
If c <> b(i) Then
Return False
End If
i += 1
Next
Return True
End Function
Private Shared Function DecodeX509PublicKey(ByVal x509Key As Byte()) As RSACryptoServiceProvider
Dim seqID As Byte() = {&H30, &HD, &H6, &H9, &H2A, &H86, _
&H48, &H86, &HF7, &HD, &H1, &H1, _
&H1, &H5, &H0}
Dim seq As Byte()
Dim mem As New MemoryStream(x509Key)
Dim binr As New BinaryReader(mem)
Dim bt As Byte
Dim twobytes As UShort
Try
twobytes = binr.ReadUInt16()
If twobytes = &H8130 Then
binr.ReadByte()
ElseIf twobytes = &H8230 Then
binr.ReadInt16()
Else
Return Nothing
End If
seq = binr.ReadBytes(15)
If Not CompareByteArrays(seq, seqID) Then
Return Nothing
End If
twobytes = binr.ReadUInt16()
If twobytes = &H8103 Then
binr.ReadByte()
ElseIf twobytes = &H8203 Then
binr.ReadInt16()
Else
Return Nothing
End If
bt = binr.ReadByte()
If bt <> &H0 Then
Return Nothing
End If
twobytes = binr.ReadUInt16()
If twobytes = &H8130 Then
binr.ReadByte()
ElseIf twobytes = &H8230 Then
binr.ReadInt16()
Else
Return Nothing
End If
twobytes = binr.ReadUInt16()
Dim lowbyte As Byte
Dim highbyte As Byte = &H0
If twobytes = &H8102 Then
lowbyte = binr.ReadByte()
ElseIf twobytes = &H8202 Then
highbyte = binr.ReadByte()
lowbyte = binr.ReadByte()
Else
Return Nothing
End If
Dim modint As Byte() = {lowbyte, highbyte, &H0, &H0}
Dim modsize As Integer = BitConverter.ToInt32(modint, 0)
Dim firstbyte As Byte = binr.ReadByte()
binr.BaseStream.Seek(-1, SeekOrigin.Current)
If firstbyte = &H0 Then
binr.ReadByte()
modsize -= 1
End If
Dim modulus As Byte() = binr.ReadBytes(modsize)
If binr.ReadByte() <> &H2 Then
Return Nothing
End If
Dim expbytes As Integer = CInt(binr.ReadByte())
Dim exponent As Byte() = binr.ReadBytes(expbytes)
Dim RSA As New RSACryptoServiceProvider()
Dim RSAKeyInfo As New RSAParameters() With {
.Modulus = modulus,
.Exponent = exponent
}
RSA.ImportParameters(RSAKeyInfo)
Return RSA
Catch e As Exception
Return Nothing
Finally
binr.Close()
End Try
End Function
Public Shared Function Encrypt(ByVal PublicKey As String, ByVal text As String) As List(Of Integer)
Dim rsa As RSACryptoServiceProvider = DecodeX509PublicKey(Convert.FromBase64String(PublicKey))
If rsa Is Nothing Then Return Nothing
Dim loc4 = rsa.Encrypt(Encoding.UTF8.GetBytes(text), False)
Dim loc5 As New List(Of Integer)
For Each b In loc4
loc5.Add(b)
Next
Return loc5
End Function
End Class
Case 3
Case 3
.Label_Statut.Text = "Connecté"
.WriteLog("[" & TimeOfDay & "]" & " ###" & " " & "La connexion a été ouverte.", Color.Green)
.ObjectValue = New HelloConnectMessage
.ObjectValue.Unpack(PacketData)
Dim Certificate As New TrustCertificate
Dim M_Certificate As New List(Of TrustCertificate)
Dim key = .ObjectValue.Key
Dim Account As String = .Text
Dim Password As String = .MDP.Text
Dim CryptedPassword As List(Of Integer)
Dim PublicKey As String = ""
Dim PublicKeyTemp As New List(Of Byte)
Dim Salt As String = .ObjectValue.Salt
For Each u In key
PublicKeyTemp.Add(u)
Next
PublicKey = Convert.ToBase64String(PublicKeyTemp.ToArray())
If Salt.Length < 32 Then
While Salt.Length < 32
Salt &= " "
End While
End If
Dim OunasManager As New OunasManager
CryptedPassword = OunasRSA.Encrypt(PublicKey, Salt & Password)
Dim Version_ As New Types.Version.Version
Version_.init(2, 5, 3, 0, 0, 0)
Dim MessageEnvoi As New IdentificationMessage
Dim Param1 As New DofusMessage
MessageEnvoi.init(Version_, "fr", Account, CryptedPassword, 0, True, True, False)
MessageEnvoi.Pack(Param1, .Socket)
j'envoi le 4 après je ne reçois rien