Salut à tous =)
Voilà, je développe mon petit bot socket en C# depuis peu, et j'ai un petit soucis avec cette fonction. Elle fail et me donne comme message exception : Données Incorrectes.
Pour infos, j'ai repris quasiment mot pour mot la fonction de Maxou, ça passe partout où il faut x) Mais semble t-il que je rempli mal le RsaKeyInfo, et du coup, ça fonctionne pas. Je post ma classe.
Cliquez pour révéler
Cliquez pour masquer
private RSACryptoServiceProvider DecodeX509PublicKey()
{
Byte[] seqID = new Byte[15] { 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00 };
switch (Key.ReadIntOn16Bits())
{
case (0x3081) :
Key.ReadByte();
break;
case (0x3082) :
Key.ReadIntOn16Bits();
break;
default :
return (null);
}
if (CompareByteArray(seqID, Key.ReadBytes(15)) == false)
return (null);
switch (Key.ReadIntOn16Bits())
{
case (0x0381) :
Key.ReadByte();
break;
case (0x0382) :
Key.ReadIntOn16Bits();
break;
default :
return (null);
}
if (Key.ReadByte() != 0)
return (null);
switch (Key.ReadIntOn16Bits())
{
case (0x3081):
Key.ReadByte();
break;
case (0x3082):
Key.ReadIntOn16Bits();
break;
default:
return (null);
}
Byte lowByte;
Byte highByte = 0x00;
switch (Key.ReadIntOn16Bits())
{
case (0x0281):
lowByte = Key.ReadByte();
break;
case (0x0282):
highByte = Key.ReadByte();
lowByte = Key.ReadByte();
break;
default:
return (null);
}
Byte[] modint = new Byte[4] {lowByte, highByte, 0x00, 0x00};
int modsize = BitConverter.ToInt32(modint, 0);
Byte firstbyte = Key.ReadByte();
Key.Moove(-1);
if (firstbyte == 0x00)
{
Key.ReadByte();
modsize -= 1;
}
Byte[] modulus = Key.ReadBytes(modsize);
if (Key.ReadByte() != 2)
return (null);
int expbytes = Convert.ToInt32(Key.ReadByte());
Byte[] exponent = Key.ReadBytes(expbytes);
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
RSAParameters RsaKeyInfo = new RSAParameters();
RsaKeyInfo.Modulus = modulus;
RsaKeyInfo.Exponent = exponent;
try
{
RSA.ImportParameters(RsaKeyInfo);
}
catch(CryptographicException e)
{
Console.WriteLine(e.Message);
return (null);
}
return (RSA);
}
A savoir que je n'utilise pas de mem ni de binary, etant donnée que la classe Key que j'ai crée me permet les mêmes action, tout fonction jusqu'à la ligne :
RSA.ImportParameters(RsaKeyInfo);
Merci ^^
Edit : J'ai cc mot pour mot maxou, je me sens débile mais bon, apparemment, c'est mon curseur dans le buffer qui était pas bien placé, fin bref x)