双向密钥加密/散列算法 [英] two-way keyed encryption/hash algorithm

查看:110
本文介绍了双向密钥加密/散列算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这种类型的事情我没有经验,所以我甚至不确定关键字(因此标题)。
基本上我需要一个双向函数

  encrypt(w,x,y)= z 

decrypt(z)= w,x,y

其中w = integer
x = string(username)
y = unix timestamp

和z =是一个8位数字(可能包括字母,规格还没有。)



我希望z不容易被猜到,容易验证。速度不是一个巨大的关注,安全性也不是。跟踪一对一关系是主要的要求。
任何资源或方向将不胜感激。



编辑



感谢您的答案,学习很多。所以要澄清,8个字符是唯一的困难要求,以及链接W - Z的能力。用户名(Y)和时间戳(Z)将被认为是蛋糕上的结冰。



我想在数学上做这个,而不是做一些数据库查找,如果可能的话。



如果我今晚必须完成这个,我可以找到一个拟合的哈希算法,并使用查找表。我只是想扩大我对这种类型事物的理解,看看我能否在数学上做到这一点。

解决方案

您只需要使用私钥对(w,x,y)的序列化进行加密。使用相同的私钥来解密它。



无论如何,z的大小不像你那样简单的界定,因为它取决于序列化的大小因为它需要是两种方式,所以你可以根据熵来对压缩做一个限制。)



你不是在寻找哈希函数,因为这显然会丢失一些信息,您将无法撤消。



编辑:由于z的大小是硬限制,因此您需要限制输入到8字节,并选择使用64位(或更少)块大小的加密技术。 Blowfish Triple DES 使用64位块,但请记住,这些算法没有得到与 AES



如果你想要一些非常简单和相当不安全的东西,只需 xor 您的输入与密钥。


I am no way experienced in this type of thing so I am not even sure of the keywords (hence the title). Basically I need a two way function

encrypt(w,x,y) = z

decrypt(z) = w, x, y

Where w = integer 
      x = string (username)
      y = unix timestamp 

and z = is an 8 digit number (possibly including letters, spec isn't there yet.)

I would like z to be not easily guessable and easily verifiable. Speed isn't a huge concern, security isn't either. Tracking one-to-one relationship is the main requirement. Any resources or direction would be appreciated.

EDIT

Thanks for the answers, learning a lot. So to clarify, 8 characters is the only hard requirement, along with the ability to link W <-> Z. The username (Y) and timestamp (Z) would be considered icing on the cake.

I would like to do this mathematically rather than doing some database looks up, if possible.

If i had to finish this tonight, I could just find a fitting hash algorithm and use a look up table. I am simply trying to expand my understanding of this type of thing and see if I could do it mathematically.

解决方案

You just need to encrypt a serialization of (w, x, y) with a private key. Use the same private key to decrypt it.

In any case, the size of z cannot be simply bounded like you did, since it depends on the size of the serialization (since it needs to be two way, there's a bound on the compression you can do, depending on the entropy).

And you are not looking for a hash function, since it would obviously lose some information and you wouldn't be able to reverse it.

EDIT: Since the size of z is a hard limit, you need to restrict the input to 8 bytes, and choose a encryption technique that use 64 bits (or less) block size. Blowfish and Triple DES use 64 bits blocks, but remember that those algorithms didn't receive the same scrutiny as AES.

If you want something really simple and quite unsecure, just xor your input with a secret key.

这篇关于双向密钥加密/散列算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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