Article View: pl.comp.lang.python
Article #28399M2crypto
From: zigi
Date: Fri, 10 Feb 2012 12:45
Date: Fri, 10 Feb 2012 12:45
72 lines
3615 bytes
3615 bytes
Witam Panowie
próbuję rozszyfrować biblitekę M2Crypto
__init__(self, alg, key, iv, op, key_as_bytes=0, d='md5',
salt='12345678', i=1, padding=1)
mam troche przykładów z neta
chociażby to
def test_AES(self):
enc = 1
dec = 0
tests = [
# test vectors from rfc 3602
#Case #1: Encrypting 16 bytes (1 block) using AES-CBC with
128-bit key
{
'KEY': '06a9214036b8a15b512e03d534120006',
'IV': '3dafba429d9eb430b422da802c9fac41',
'PT': 'Single block msg',
'CT': 'e353779c1079aeb82708942dbe77181a',
},
#Case #2: Encrypting 32 bytes (2 blocks) using AES-CBC
with 128-bit key
{
'KEY': 'c286696d887c9aa0611bbb3e2025a45a',
'IV': '562e17996d093d28ddb3ba695a2e6f58',
'PT':
unhexlify('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'),
'CT':
'd296cd94c2cccf8a3a863028b5e1dc0a7586602d253cfff91b8266bea6d61ab1',
},
#Case #3: Encrypting 48 bytes (3 blocks) using AES-CBC
with 128-bit key
{
'KEY': '6c3ea0477630ce21a2ce334aa746c2cd',
'IV': 'c782dc4c098c66cbd9cd27d825682c81',
'PT': 'This is a 48-byte message (exactly 3 AES blocks)',
'CT':
'd0a02b3836451753d493665d33f0e8862dea54cdb293abc7506939276772f8d5021c19216bad525c8579695d83ba2684',
},
]
# Test with padding
for test in tests:
# encrypt
k=EVP.Cipher(alg='aes_128_cbc',
key=unhexlify(test['KEY']), iv=unhexlify(test['IV']), op=enc)
pbuf=cStringIO.StringIO(test['PT'])
cbuf=cStringIO.StringIO()
ciphertext = hexlify(self.cipher_filter(k, pbuf, cbuf))
cipherpadding = ciphertext[len(test['PT']) * 2:]
ciphertext = ciphertext[:len(test['PT']) * 2] # Remove the
padding from the end
pbuf.close()
cbuf.close()
self.assertEqual(ciphertext, test['CT'])
teraz tak
'KEY': 'c286696d887c9aa0611bbb3e2025a45a' jest tu wbity na stałe
rozumiem iż mogę do tego wykorzystać M2Crypto.rand ??
czy np skorzystać tu z klucza generowanego
M2Crypto.RSA.gen_key (1024, 65537)
pozatym ni wiem do czego służy , iv, op w przykładnie też jest na
stałe wbite.
Może ktoś miał do czynienia z tematem
Pozdrawiam.
Technical Details
Message-ID:
<96bc92ab-d565-4d28-8f54-c3dc3e3dde7e@ge5g2000vbb.googlegroups.com>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!wsisiz.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!goblin1!goblin.stu.neva.ru!postnews.google.com!ge5g2000vbb.googlegroups.com!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!wsisiz.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!goblin1!goblin.stu.neva.ru!postnews.google.com!ge5g2000vbb.googlegroups.com!not-for-mail From: zigi <cezar4846@gmail.com> Newsgroups: pl.comp.lang.python Subject: M2crypto Date: Fri, 10 Feb 2012 04:45:12 -0800 (PST) Organization: http://groups.google.com Lines: 75 Message-ID: <96bc92ab-d565-4d28-8f54-c3dc3e3dde7e@ge5g2000vbb.googlegroups.com> NNTP-Posting-Host: 93.159.33.61 Mime-Version: 1.0 X-Trace: posting.google.com 1328877913 10147 127.0.0.1 (10 Feb 2012 12:45:13 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 10 Feb 2012 12:45:13 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: ge5g2000vbb.googlegroups.com; posting-host=93.159.33.61; posting-account=KO8BxgoAAACCbIevmmXkvGNLzCGU-P0N User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: ASELCHRU X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7,gzip(gfe) Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit