Je l'extrait suivant qui décrypte une chaîne cryptée avec 3DES:décryptez un cryptogramme avec TripleDES KEY statique et IV à travers l'outil OpenSSL
private static byte[] KEY_192 = new byte[]
{
37, 19, 88, 164, 71, 3, 227, 30, 19,
174, 45, 84, 23, 253, 149, 108, 12,
107, 16, 192, 98, 22, 179, 200
};
private static byte[] IV_192 = new byte[]
{
47, 108, 239, 71, 33, 98, 177, 13,
36, 51, 69, 88, 189, 17, 210, 14,
174, 230, 20, 60, 174, 100, 12, 22
};
public static string DecryptTripleDES(string value)
{
if (!string.IsNullOrEmpty(value))
{
System.Security.Cryptography.TripleDESCryptoServiceProvider cryptoProvider = new System.Security.Cryptography.TripleDESCryptoServiceProvider();
byte[] buffer = System.Convert.FromBase64String(value);
System.IO.MemoryStream ms = new System.IO.MemoryStream(buffer);
System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, cryptoProvider.CreateDecryptor(DataEncryptionEngine.KEY_192, DataEncryptionEngine.IV_192), System.Security.Cryptography.CryptoStreamMode.Read);
System.IO.StreamReader sr = new System.IO.StreamReader(cs);
return sr.ReadToEnd();
}
return null;
}
Je suis en train de le reproduire avec OpenSSL ou Ruby, mais sans chance, un exemple de chaîne cryptée base64 codée est:
JDiLOoP3iIY=
Lorsque j'essaie cela sous Linux, j'obtiens l'erreur suivante.
$ echo JDiLOoP3iIY = | openssl enc -d -des3 -a -K 371988164713227301917445842325314910812107161929822179200 -iv 471082397133981771336516988189172101417423020601741001222; chaîne hexadécimale est trop long invalide valeur hexadécimale iv
Que manque-t-il? Merci!
Edit: Si elle aide, c'est la fonction qui encrypte la chaîne:
public static string EncryptTripleDES(string value)
{
if (!string.IsNullOrEmpty(value))
{
System.Security.Cryptography.TripleDESCryptoServiceProvider cryptoProvider = new System.Security.Cryptography.TripleDESCryptoServiceProvider();
System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, cryptoProvider.CreateEncryptor(DataEncryptionEngine.KEY_192, DataEncryptionEngine.IV_192), System.Security.Cryptography.CryptoStreamMode.Write);
System.IO.StreamWriter sw = new System.IO.StreamWriter(cs);
sw.Write(value);
sw.Flush();
cs.FlushFinalBlock();
ms.Flush();
return System.Convert.ToBase64String(ms.GetBuffer(), 0, System.Convert.ToInt32(ms.Length));
}
return null;
}
Essayé ce sur rubis trop, même, je reçois 'mauvais Décrypter'
#!/usr/bin/env ruby
require 'openssl'
require 'base64'
string = 'JDiLOoP3iIY='
def decrypt(cpass)
cipher = OpenSSL::Cipher::Cipher.new("des-ede-cbc")
cipher.decrypt
cipher.key = "251358A44703E31E13AE2D5417FD956C0C6B10C06216B3C8"
cipher.iv = "2F6CEF472162B10D24334558BD11D20EAEE6143CAE640C16"
return cipher.update(Base64.decode64(cpass)) + cipher.final
end
decrypted = decrypt(string)
puts "decrypted string: #{decrypted}"
3DES a besoin 64 IVs de bits, et non pas 192 IVs bits. – CodesInChaos
Je sais cela, mais voici comment est utilisé dans ce code ... – bsteo