que quelqu'un peut me fournir le code pour crypter/décrypter en utilisant m2crypto AES256 CBC en utilisant PythonM2Crypto Crypter/Décrypter utilisant AES256
Répondre
Quand il vient à rien de sécurité bat la lecture de la documentation.
http://chandlerproject.org/bin/view/Projects/MeTooCrypto
Même si je prenais le temps de comprendre et de rendre le code parfait pour vous de copier et coller, vous auriez aucune idée si je faisais un bon travail ou non. Pas très utile je sais, mais je vous souhaite bonne chance et sécuriser les données.
Ce lien n'est plus valide. –
La documentation de M2Crypto est terrible. Parfois, la documentation OpenSSL (m2crypto wraps OpenSSL) peut aider. Votre meilleur pari est de regarder les tests unitaires M2Crypto - http://svn.osafoundation.org/m2crypto/trunk/tests/test_evp.py - recherchez la méthode test_AES()
.
+1 ... joe, cette réponse a été très appréciée aujourd'hui alors que je travaillais sur un projet d'animal de compagnie. Je commençais à penser que j'étais fou quand je regardais les docs de M2Crypto et, euh, l'API epydoc peu commentée; sûrement, il me manquait quelque chose d'évident! Merci d'avoir restauré ma foi. –
Jetez un oeil à m2secret:
Petit utilitaire et module pour et des données de cryptage en utilisant algorithmes de déchiffrement-clé symétrique. Par défaut utilise AES 256 bits (Rijndael) en utilisant CBC, mais certaines options sont configurables. Algorithme PBKDF2 utilisé pour dériver la clé à partir du mot de passe.
def encrypt_file(key, in_filename, out_filename,iv):
cipher=M2Crypto.EVP.Cipher('aes_256_cfb',key,iv, op=1)
with open(in_filename, 'rb') as infile:
with open(out_filename, 'wb') as outfile:
outfile.write(b)
while True:
buf = infile.read(1024)
if not buf:
break
outfile.write(cipher.update(buf))
outfile.write(cipher.final())
outfile.close()
infile.close()
def decrypt_file(key, in_filename, out_filename,iv):
cipher = M2Crypto.EVP.Cipher("aes_256_cfb",key , iv, op = 0)
with open(in_filename, 'rb') as infile:
with open(out_filename, 'wb') as outfile:
while True:
buf = infile.read(1024)
if not buf:
break
try:
outfile.write(cipher.update(buf))
except:
print "here"
outfile.write(cipher.final())
outfile.close()
infile.close()
J'utilise wrapper autour M2Crypto suivante (empruntée à cryptography.io):
import os
import base64
import M2Crypto
class SymmetricEncryption(object):
@staticmethod
def generate_key():
return base64.b64encode(os.urandom(48))
def __init__(self, key):
key = base64.b64decode(key)
self.iv = key[:16]
self.key = key[16:]
def encrypt(self, plaintext):
ENCRYPT = 1
cipher = M2Crypto.EVP.Cipher(alg='aes_256_cbc', key=self.key, iv=self.iv, op=ENCRYPT)
ciphertext = cipher.update(plaintext) + cipher.final()
return base64.b64encode(ciphertext)
def decrypt(self, cyphertext):
DECRYPT = 0
cipher = M2Crypto.EVP.Cipher(alg='aes_256_cbc', key=self.key, iv=self.iv, op=DECRYPT)
plaintext = cipher.update(base64.b64decode(cyphertext)) + cipher.final()
return plaintext
- 1. Python M2Crypto EC Support
- 2. m2crypto lance "TypeError: dans la méthode 'x509_req_set_pubkey'"
- 3. Windows XP prend-il en charge TLS1.1 avec AES256?
- 4. Comment désactiver la redirection d'URL en Python lors de l'utilisation de M2Crypto SSL?
- 5. rappel before_add utilisant nested_attributes
- 6. en utilisant DebugDiag
- 7. En utilisant RangeValidator l'octet
- 8. comparaison en utilisant strcmp
- 9. Flash utilisant AS3.0
- 10. En utilisant $ _GET & _POST
- 11. Webservice utilisant Seam
- 12. C# webRequest utilisant cookies
- 13. En utilisant SubSonic2.2
- 14. Word Automation utilisant WIN32OLE
- 15. sortie en utilisant innerHTML
- 16. Résultats bizarres utilisant P4COM
- 17. Grandes applications utilisant NHibernate
- 18. JTable utilisant Swing
- 19. IMEI utilisant Javascript
- 20. Tableau déroulant utilisant jQuery
- 21. Mailmerge utilisant OpenOffice
- 22. QT4 QFileSystemWatcher utilisant Ruby
- 23. Certains ORM utilisant PDO?
- 24. Viewbox alternative utilisant Winforms
- 25. Sqlite3 utilisant dans l'iPhone
- 26. en utilisant DirectoryWalker
- 27. image en utilisant .ashx
- 28. Set Environment.SpecialFolder.LocalApplicationData utilisant C#
- 29. producteur-consommateur utilisant affectation
- 30. utilisant OleDB vs SqlServerCe
Vous pouvez consulter un [à ce poste] [1]. [1]: http://stackoverflow.com/questions/5003626/problem-with-m2cryptos-aes – ohe