开发者

How can I create an encryptor and decryptor that contains only letter and numbers?The same as this (ABQIAAAA5SlC01zPdiQe2c6gr56AAhSc)

开发者 https://www.devze.com 2023-02-03 23:03 出处:网络
Hi how can I encrypt and decrypt strings. And the output of the encryp开发者_JAVA技巧ted string is alphanumeric and doesn\'t contain any special characters.Same as this example.

Hi how can I encrypt and decrypt strings. And the output of the encryp开发者_JAVA技巧ted string is alphanumeric and doesn't contain any special characters.Same as this example.

ABQIAAAA5SlC01zPdiQe2c6gr56AAhScFBH9YSIKcAjU8YFSuTREdFBSWYOldpPAPQqWTfiiPcWJL6ddpLw.


Encrypt it first; And then base 64 encode the resulting ciphertext. The entire purpose of base 64 is to transform non printable data into printable data.

So you will use it like the following:

Plaintext -> Encrypt -> Base64 Endode = Ciphertext

Ciphertext -> Base64 Decode -> Decrypt = Plaintext


try encrypting first chosing any algorithm like DES, Triple-des, etc. and then encoding using the BASE64.

The Base64 encoding is designed to represent arbitrary sequences of octets in a form that need not be humanly readable


As a note, base 64 encoding includes paddings which are non alpha numeric, ie the equal sign so...

Base 62 encode your data and then use whatever you want to encrypt it. Assign binary values to a-z A-Z 0-9 and then use the same techniques as base 64 encoding to actually encode your data. It's not as standard as Base64 but it's only letters and numbers.


Please refer to my answer here, which may help. What I am doing is first encrypting the string with any mcrypt cipher (like blowfish), and then re-encrypting it using str2hex. Now the string contains only A-Z and 0-9, no special characters. While decrypting, first decrypt using hex2str, then decrypt using the same cipher used to encrypt. I used it in codeigniter, but I guess the concept can be implemented anywhere. I hope this could be of some help.

0

精彩评论

暂无评论...
验证码 换一张
取 消