Esempio n. 1
0
def Decrypt(data):

    data = util.h2b(data)
    cipher = Cipher(alg='aes_128_ecb', key=PRIVATE_KEY, iv=iv, op=DECRYPT_OP)
    buf = cipher.update(data)
    buf = buf + cipher.final()
    del cipher
    return buf
Esempio n. 2
0
def Decrypt(data):
  '使用aes_128_ecb算法对数据解密'
  # 将密文从16进制转为字节流
  data = util.h2b(data)
  cipher = Cipher(alg = 'aes_128_ecb', key = PRIVATE_KEY, iv = iv, op = DECRYPT_OP)
  buf = cipher.update(data)
  buf = buf + cipher.final()
  del cipher
  return buf 
Esempio n. 3
0
	def AESDecrypt(cls, data):  
	  '使用aes_128_ecb算法对数据解密'  
	  # 将密文从16进制转为字节流  
	  data = util.h2b(data)  
	  cipher = Cipher(alg = 'aes_128_ecb', key = cls.privateKey, iv = cls.iv, op = DEC)  
	  txt = cipher.update(data)  
	  txt = txt + cipher.final()  
	  del cipher  
	  return txt
Esempio n. 4
0
def decrypt(data):
	iv = 'b2b5b1d373b4433c' # app id
	KEY = '61e1e18779d444ed4ee6b36946f0d898' # app secret
	mode = AES.MODE_CBC
	data = util.h2b(data)
	decryptor = AES.new(KEY, mode, IV=iv)
	plain = decryptor.decrypt(data)
	plain = "".join([ plain.strip().rsplit("}" , 1)[0] ,  "}"] )
	oauth_state = json.loads(plain)
	return oauth_state
Esempio n. 5
0
def decrypt(data):
    iv = "9b738aa2ee18145a"  # app id
    KEY = "298fe57f669647ffe92ee1deba8b944e"  # app secret
    mode = AES.MODE_CBC
    data = util.h2b(data)
    decryptor = AES.new(KEY, mode, IV=iv)
    plain = decryptor.decrypt(data)
    plain = "".join([plain.strip().rsplit("}", 1)[0], "}"])
    oauth_state = json.loads(plain)
    return oauth_state
Esempio n. 6
0
def decrypt(data):
	iv = '3288d370af0a77c5'
	KEY = 'f9d6fe00a9450f5d64c5c4fd288b8119'
	mode = AES.MODE_CBC
	data = util.h2b(data)
	decryptor = AES.new(KEY, mode, IV=iv)
	plain = decryptor.decrypt(data)
	plain = "".join([ plain.strip().rsplit("}" , 1)[0] ,  "}"] )
	oauth_state = json.loads(plain)
	return oauth_state
Esempio n. 7
0
def decrypt(data):
	iv = '433acf3969f659d1' # app id
	KEY = '038fa8231348f42966b95ee52f56fbf7' # app secret
	mode = AES.MODE_CBC
	data = util.h2b(data)
	decryptor = AES.new(KEY, mode, IV=iv)
	plain = decryptor.decrypt(data)
	plain = "".join([ plain.strip().rsplit("}" , 1)[0] ,  "}"] )
	oauth_state = json.loads(plain)
	return oauth_state
Esempio n. 8
0
def Decrypt(data):
  # 将密文从16进制转为字节流
  data = util.h2b(data)
  cipher = Cipher(alg = 'aes_128_ecb', key = PRIVATE_KEY, iv = iv, op = DECRYPT_OP)
  buf = cipher.update(data)
  buf = buf + cipher.final()
  del cipher
  return buf


# print Decrypt('6C0D072989D9F7271EF1BD5AA1C830F2')
Esempio n. 9
0
def decrypt(data):
	iv = '6baadc29cf37062a' # app id
	KEY = '9acfba94ad8877ed858e9acf01fe3acb' # app secret
	mode = AES.MODE_CBC
	data = util.h2b(data)
	decryptor = AES.new(KEY, mode, IV=iv)
	plain = decryptor.decrypt(data)
	print plain
	plain = "".join([ plain.strip().rsplit("}" , 1)[0] ,  "}"] )
	oauth_state = json.loads(plain)
	return oauth_state
Esempio n. 10
0
class HMACTestCase(unittest.TestCase):
    data1=['', 'More text test vectors to stuff up EBCDIC machines :-)', \
           h2b("b760e92d6662d351eb3801057695ac0346295356")]

    data2=[h2b('0b'*16), "Hi There", \
           h2b("675b0b3a1b4ddf4e124872da6c2f632bfed957e9")]

    data3=['Jefe', "what do ya want for nothing?", \
           h2b("effcdf6ae5eb2fa2d27416d5f184df9c259a7c79")]

    data4=[h2b('aa'*16), h2b('dd'*50), \
           h2b("d730594d167e35d5956fd8003d0db3d3f46dc7bb")]

    data = [data1, data2, data3, data4]

    def test_simple(self):
        algo = 'sha1'
        for d in self.data:
            h = EVP.HMAC(d[0], algo)
            h.update(d[1])
            ret = h.final()
            self.assertEqual(ret, d[2])
        self.assertRaises(ValueError, EVP.HMAC, d[0], algo='nosuchalgo')

    def make_chain_HMAC(self, key, start, input, algo='sha1'):
        chain = []
        hmac = EVP.HMAC(key, algo)
        hmac.update( ` start `)
        digest = hmac.final()
        chain.append((digest, start))
        for i in input:
            hmac.reset(digest)
            hmac.update( ` i `)
            digest = hmac.final()
            chain.append((digest, i))
        return chain

    def make_chain_hmac(self, key, start, input, algo='sha1'):
        from M2Crypto.EVP import hmac
        chain = []
        digest = hmac(key, ` start `, algo)
        chain.append((digest, start))
        for i in input:
            digest = hmac(digest, ` i `, algo)
            chain.append((digest, i))
        return chain

    def verify_chain_hmac(self, key, start, chain, algo='sha1'):
        from M2Crypto.EVP import hmac
        digest = hmac(key, ` start `, algo)
        c = chain[0]
        if c[0] != digest or c[1] != start:
            return 0
        for d, v in chain[1:]:
            digest = hmac(digest, ` v `, algo)
            if digest != d:
                return 0
        return 1

    def verify_chain_HMAC(self, key, start, chain, algo='sha1'):
        hmac = EVP.HMAC(key, algo)
        hmac.update( ` start `)
        digest = hmac.final()
        c = chain[0]
        if c[0] != digest or c[1] != start:
            return 0
        for d, v in chain[1:]:
            hmac.reset(digest)
            hmac.update( ` v `)
            digest = hmac.final()
            if digest != d:
                return 0
        return 1

    def test_complicated(self):
        make_chain = self.make_chain_hmac
        verify_chain = self.verify_chain_hmac
        key = 'numero uno'
        start = 'zeroth item'
        input = ['first item', 'go go go', 'fly fly fly']
        chain = make_chain(key, start, input)
        self.assertEquals(verify_chain('some key', start, chain), 0)
        self.assertEquals(verify_chain(key, start, chain), 1)
Esempio n. 11
0
class HMACTestCase(unittest.TestCase):
    data1=['', 'More text test vectors to stuff up EBCDIC machines :-)', \
           h2b("e9139d1e6ee064ef8cf514fc7dc83e86")]

    data2=[h2b('0b'*16), "Hi There", \
           h2b("9294727a3638bb1c13f48ef8158bfc9d")]

    data3=['Jefe', "what do ya want for nothing?", \
           h2b("750c783e6ab0b503eaa86e310a5db738")]

    data4=[h2b('aa'*16), h2b('dd'*50), \
           h2b("0x56be34521d144c88dbb8c733f0e8b3f6")]

    data = [data1, data2, data3, data4]

    def test_simple(self):
        algo = 'md5'
        for d in self.data:
            h = EVP.HMAC(d[0], algo)
            h.update(d[1])
            ret = h.final()
            self.assertEqual(ret, d[2])
        self.assertRaises(ValueError, EVP.HMAC, d[0], algo='nosuchalgo')

    def make_chain_HMAC(self, key, start, input, algo='sha1'):
        chain = []
        hmac = EVP.HMAC(key, algo)
        hmac.update( ` start `)
        digest = hmac.final()
        chain.append((digest, start))
        for i in input:
            hmac.reset(digest)
            hmac.update( ` i `)
            digest = hmac.final()
            chain.append((digest, i))
        return chain

    def make_chain_hmac(self, key, start, input, algo='sha1'):
        from M2Crypto.EVP import hmac
        chain = []
        digest = hmac(key, ` start `, algo)
        chain.append((digest, start))
        for i in input:
            digest = hmac(digest, ` i `, algo)
            chain.append((digest, i))
        return chain

    def verify_chain_hmac(self, key, start, chain, algo='sha1'):
        from M2Crypto.EVP import hmac
        digest = hmac(key, ` start `, algo)
        c = chain[0]
        if c[0] != digest or c[1] != start:
            return 0
        for d, v in chain[1:]:
            digest = hmac(digest, ` v `, algo)
            if digest != d:
                return 0
        return 1

    def verify_chain_HMAC(self, key, start, chain, algo='sha1'):
        hmac = EVP.HMAC(key, algo)
        hmac.update( ` start `)
        digest = hmac.final()
        c = chain[0]
        if c[0] != digest or c[1] != start:
            return 0
        for d, v in chain[1:]:
            hmac.reset(digest)
            hmac.update( ` v `)
            digest = hmac.final()
            if digest != d:
                return 0
        return 1

    def test_complicated(self):
        make_chain = self.make_chain_hmac
        verify_chain = self.verify_chain_hmac
        key = 'numero uno'
        start = 'zeroth item'
        input = ['first item', 'go go go', 'fly fly fly']
        chain = make_chain(key, start, input)
        self.assertEquals(verify_chain('some key', start, chain), 0)
        self.assertEquals(verify_chain(key, start, chain), 1)
Esempio n. 12
0
#!/usr/bin/env python

"""HMAC demonstration.

Copyright (c) 1999-2003 Ng Pheng Siong. All rights reserved."""

from M2Crypto import EVP, Rand
from M2Crypto.util import h2b

data1 = ["", "More text test vectors to stuff up EBCDIC machines :-)", h2b("e9139d1e6ee064ef8cf514fc7dc83e86")]

data2 = [h2b("0b" * 16), "Hi There", h2b("9294727a3638bb1c13f48ef8158bfc9d")]

data3 = ["Jefe", "what do ya want for nothing?", h2b("750c783e6ab0b503eaa86e310a5db738")]

data4 = [h2b("aa" * 16), h2b("dd" * 50), h2b("56be34521d144c88dbb8c733f0e8b3f6")]

data = [data1, data2, data3, data4]


def test():
    print "testing hmac"
    algo = "md5"
    for d in data:
        h = EVP.HMAC(d[0], algo)
        h.update(d[1])
        ret = h.final()
        if ret != d[2]:
            print data.index(d) + 1, "not ok"
        else:
            print "ok"