0

I am trying to hide an actual string. So, I am choosing encoding mechanism to encode it. Is there any best Encryption/Decryption Algorithms to deal with it ?

How can I do it in Python? The encoded string should be of length 10 (encoded string should be alphanumeric).

I just tried with some code available in Google. How can I format it to get desired output needed ?

from Crypto.Cipher import AES
import base64

MASTER_KEY="Some-long-base-key-to-use-as-encyrption-key"

def encrypt_val(clear_text):
    enc_secret = AES.new(MASTER_KEY[:32])
    tag_string = (str(clear_text) +
                  (AES.block_size -
                   len(str(clear_text)) % AES.block_size) * "\0")
    cipher_text = base64.b64encode(enc_secret.encrypt(tag_string))

    print cipher_text

encrypt_val("abcd_10.10.10.10_abcdefghijk")

Output for above : ytZyd3PGRg7POl80qlF8Oi79gwj7U31D/rsC50EDCt4=
9
  • 3
    1) "couldn't obtain desired output needed" is useless. Please say specifically what output or error you got vs what you expected to get. 2) Since AES is not shipped with Python, I need to verify whether you did, in fact, install pycrypto module which lets you use AES? Commented Nov 30, 2016 at 8:19
  • 1
    Truncating the master key to 32 bytes is not a good idea. Use a key derivation function. Commented Nov 30, 2016 at 9:03
  • @Amadan : Thanks for pointing it. I have corrected it. And edited the question with input and output too. Can you please help me in this regard. Commented Nov 30, 2016 at 9:04
  • Is that desired output or actual output? (And you never answered about pycrypto.) Commented Nov 30, 2016 at 9:05
  • 3
    @Jackie Voting to close now, for multiple reasons: (1) You still haven't adequately explained why the output of this code isn't what you expected. (2) You appear to be asking for an encryption function that compresses strings of any length to just 10 bytes. No such function exists. (3) The code you provided actually works (albeit with a truncated master key, which is a bad idea as I pointed out already). Commented Nov 30, 2016 at 9:27

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.