Python中的CMACAES

2024-05-16 04:15:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在Django应用程序中实现与此api的集成。http://pdn.pearson.com/pearson-learningstudio/apis/authentication/authentication-use-cases/use-case-submit-request-using-oauth2-assertion_x

除了使用断言身份验证方法外,几乎所有的方法都可以工作。我需要使用CMAC-AES加密断言字符串,但我不知道如何去做。在

他们所有的示例代码都使用这些语言的内置库,我找不到任何库可以让我在Python中实现这一点。我在谷歌上搜了一整天,却一无所获。在

有人知道我在哪里能找到一个图书馆让我做这件事吗?或者如何解决它

谢谢

-亚历克斯


Tags: django方法comapi应用程序httpauthenticationuse
2条回答

PyCrypto的当前alpha版本包含CMAC作为模块^{}。在

例如:

from Crypto.Hash import CMAC
from Crypto.Cipher import AES

secret = b'Sixteen byte key'
cobj = CMAC.new(secret, ciphermod=AES)
cobj.update(b'Hello')
print cobj.hexdigest() 

PyCryptoPlus库实现CMAC-AES。这是从AES.py公司公司名称:

 CMAC EXAMPLE:
      -
NIST publication 800-38B: http://csrc.nist.gov/publications/nistpubs/800-38B/Updated_CMAC_Examples.pdf

>>> key = '2b7e151628aed2a6abf7158809cf4f3c'.decode('hex')
>>> plaintext = '6bc1bee22e409f96e93d7e117393172a'.decode('hex')
>>> cipher = AES.new(key,AES.MODE_CMAC)
>>> cipher.encrypt(plaintext).encode('hex')
'070a16b46b4d4144f79bdd9dd04a287c'

代码:http://repo.or.cz/w/python-cryptoplus.git/tree/HEAD

相关问题 更多 >