java 的cipher AES/CBC/PKCS5Padding 加密后,使用openssl的AES_cbc_encrypt无法解密
1个回答
展开全部
你看一下这个例子吧。可以参考下面的地址:前面加上http,把句号改成点。
likang。me/blog/2013/06/05/python-pycrypto-aes-ecb-pkcs-5/
# -*- coding: utf-8 -*-
from Crypto.Cipher import AES
import os
BS = AES.block_size
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
unpad = lambda s : s[0:-ord(s[-1])]
key = os.urandom(16) # the length can be (16, 24, 32)
text = 'to be encrypted'
cipher = AES.new(key)
encrypted = cipher.encrypt(pad(text)).encode('hex')
print encrypted # will be something like 'f456a6b0e54e35f2711a9fa078a76d16'
decrypted = unpad(cipher.decrypt(encrypted.decode('hex')))
print decrypted # will be 'to be encrypted'
likang。me/blog/2013/06/05/python-pycrypto-aes-ecb-pkcs-5/
# -*- coding: utf-8 -*-
from Crypto.Cipher import AES
import os
BS = AES.block_size
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
unpad = lambda s : s[0:-ord(s[-1])]
key = os.urandom(16) # the length can be (16, 24, 32)
text = 'to be encrypted'
cipher = AES.new(key)
encrypted = cipher.encrypt(pad(text)).encode('hex')
print encrypted # will be something like 'f456a6b0e54e35f2711a9fa078a76d16'
decrypted = unpad(cipher.decrypt(encrypted.decode('hex')))
print decrypted # will be 'to be encrypted'
追问
你没看懂问题,java的加密没有问题,只是java加密后,无法用c的openssl来解密。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询