加密短字符串? [英] Encrypting a short string?

查看:157
本文介绍了加密短字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在尝试设计一个加密/混淆短字符串的方案

基本上包含用户的用户名来自

数据库的记录号。我正在使用此加密字符串来识别来自

用户的电子邮件。 (字符串将在电子邮件的主题行中)。


我想弄清楚我应该用哪种方法来加密

数据。这个字符串长度不到20个字符,我希望加密版本大小相同。


我试过DES加密模块,但密文长到

在这种情况下可用。


有什么建议吗?


谢谢!

Hi,

I''m trying to devise a scheme to encrypt/obfuscate a short string that
basically contains the user''s username and record number from the
database. I''m using this encrypted string to identify emails from a
user. (the string will be in the subject line of the email).

I''m trying to figure out which approach I should use to encrypt the
data. The string will be less than 20 characters long, and I''d like
the encrypted version to be about the same size.

I tried DES in the Crypto module, but the cipher text was to long to
be usable in this case.

Any suggestions?

Thanks!

推荐答案

erikcw napisal(a):
erikcw napisal(a):




我正在尝试设计一个加密/混淆短字符串的方案

基本上包含用户的用户名和记录号

数据库。我正在使用此加密字符串来识别来自

用户的电子邮件。 (字符串将在电子邮件的主题行中)。


我想弄清楚我应该用哪种方法来加密

数据。这个字符串长度不到20个字符,我希望加密版本大小相同。


我试过DES加密模块,但密文长到

在这种情况下可用。


有什么建议吗?


谢谢!
Hi,

I''m trying to devise a scheme to encrypt/obfuscate a short string that
basically contains the user''s username and record number from the
database. I''m using this encrypted string to identify emails from a
user. (the string will be in the subject line of the email).

I''m trying to figure out which approach I should use to encrypt the
data. The string will be less than 20 characters long, and I''d like
the encrypted version to be about the same size.

I tried DES in the Crypto module, but the cipher text was to long to
be usable in this case.

Any suggestions?

Thanks!



如何


>> hashlib.sha256(" jo ******** @ example.com | 293726783 4")。hexdigest()[:20]
>>hashlib.sha256("jo********@example.com|293726783 4").hexdigest()[:20]



问候,

Marek

Regards,
Marek


2月11日,3: 07 pm,marek.ro ... @ wp.pl写道:
On Feb 11, 3:07 pm, marek.ro...@wp.pl wrote:

erikcw napisal(a):
erikcw napisal(a):


Hi,


我正在尝试设计一个加密/混淆一个短字符串的方案

基本上包含来自

数据库的用户的用户名和记录号。我正在使用此加密字符串来识别来自

用户的电子邮件。 (该字符串将位于电子邮件的主题行中)。
I''m trying to devise a scheme to encrypt/obfuscate a short string that
basically contains the user''s username and record number from the
database. I''m using this encrypted string to identify emails from a
user. (the string will be in the subject line of the email).


我想弄清楚我应该用哪种方法来加密

数据。该字符串长度不到20个字符,我希望加密版本的大小相同。


I''m trying to figure out which approach I should use to encrypt the
data. The string will be less than 20 characters long, and I''d like
the encrypted version to be about the same size.


我在加密模块中尝试过DES,但密文长到

在这种情况下可用。
I tried DES in the Crypto module, but the cipher text was to long to
be usable in this case.


有什么建议吗?
Any suggestions?


谢谢!
Thanks!



怎么样


> hashlib.sha256(" john.sm ... @ example.com | 2937267834")。hexdigest()[:20]
>hashlib.sha256("john.sm...@example.com|2937267834 ").hexdigest()[:20]



问候,

Marek


Regards,
Marek



感谢Marek,


但这不可能是逆转了吧?我希望能够解密

数据而不必将哈希值存储在我的数据库中......

Thanks Marek,

But that can''t be reversed, right? I''d like to be able to decrypt the
data instead of having to store the hash in my database...


erikcw< ;呃*********** @ gmail.comwrites:
erikcw <er***********@gmail.comwrites:

数据库。我正在使用此加密字符串来识别来自

用户的电子邮件。 (该字符串将位于电子邮件的主题行中)。
database. I''m using this encrypted string to identify emails from a
user. (the string will be in the subject line of the email).



1.我希望你不要试图向任何人发送垃圾邮件。

2.如果用户编辑主题行会怎样?

1. I hope you''re not trying to spam anyone.
2. What happens if the user edits the subject line?


我想弄清楚我应该用哪种方法来加密

数据。该字符串长度不到20个字符,我希望加密版本的大小相同。


I''m trying to figure out which approach I should use to encrypt the
data. The string will be less than 20 characters long, and I''d like
the encrypted version to be about the same size.



根据正常的安全要求,你不能这样做。密文

必须比明文长,因为你不希望对手

能够判断两个明文是否相同。因此,你需要为每个明文附加一些随机填充。另外,你想要将biphertext编码为打印字符,b / b
通常你会把输入视为二进制,所以有一些

进一步扩展。

Under normal security requirements you cannot do this. The ciphertext
has to be longer than the plaintext since you don''t want the opponent
to be able to tell whether two plaintexts are the same. Therefore you
have to attach some random padding to each plaintext. Also, you
presumably want the ciphertext to be encoded as printing characters,
while normally you''d treat the input as binary, so there is some
further expansion.


这篇关于加密短字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆