저는 암호화가 새롭기 때문에 'ABC123'
과 같은 간단한 문자열을 '3d3cf25845f3aae505bafbc1c8f16d0bfdea7d70f6b141c21726da8d'
과 같이 인코딩해야합니다. 나는이 시도보다, 내가 더 이상 뭔가가 필요간단한 문자열을 인코딩/디코딩하는 방법
>>> import base64
>>> q = 'ABC123'
>>> w = base64.encodestring(q)
>>> w
'QUJDMTIz\n'
그러나 짧은입니다 :
는 내가 처음이 시도
>>> import hashlib
>>> a = hashlib.sha224(q)
>>> a.hexdigest()
'3d3cf25845f3aae505bafbc1c8f16d0bfdea7d70f6b141c21726da8d'
이 좋은,하지만 지금은 방법을 모른다 그것을 다시 변환합니다. 어떤 사람이이 예제를 보거나 다른 것을 제안 할 수 있다면, 작은 문자열을 더 오랜 시간에 인코딩/디코딩 할 수있는 방법이 훌륭합니다. plockc
답변에 따라
UPDATE
나는 이런 짓을, 그리고 그것을 작동하는 것 같다 :
from Crypto.Cipher import AES # encryption library
BLOCK_SIZE = 32
# the character used for padding--with a block cipher such as AES, the value
# you encrypt must be a multiple of BLOCK_SIZE in length. This character is
# used to ensure that your value is always a multiple of BLOCK_SIZE
PADDING = '{'
# one-liner to sufficiently pad the text to be encrypted
pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
# one-liners to encrypt/encode and decrypt/decode a string
# encrypt with AES, encode with base64
EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
# create a cipher object using the random secret
cipher = AES.new('aaaaaaaaaa123456')
# encode a string
encoded = EncodeAES(cipher, 'ABC123')
print 'Encrypted string: %s' % encoded
# decode the encoded string
decoded = DecodeAES(cipher, encoded)
print 'Decrypted string: %s' % decoded
해시가 의미하는 바가 아닙니다. – SLaks
보안은 _hard_입니다. 어떤 시나리오에서 방어하려고합니까? – SLaks
계정 ID를 더 오래 인코딩해야하고 필요할 때 다시 디코딩해야합니다. – Vor