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

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

问题描述

我没有办法经历了这种类型的事情,所以我甚至不知道的关键字(因此标题)中。 基本上,我需要一个双向的功能

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 

和z =是一个8位数字(可能包括信件,规范现在还没有。)

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

我想Z到不容易被猜到的,并容易验证。速度不是一个的巨大的关注,安全是没有。跟踪一对一的关系是主要的要求。 任何资源或方向将AP preciated。

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.

修改

感谢您的答案,学习了很多。所以,以澄清,8字是唯一的硬性要求,连同链接的W&所述的能力; - > Z的用户名(Y)和时间戳(Z)将被认为是锦上添花

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.

推荐答案

您只需要对(W,X,Y)的序列化与私有密钥加密。使用相同的私钥进行解密。

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

在任何情况下,z的大小不能简单地界定像你一样,因为它取决于序列的大小(因为它需要双向的,有一个绑定在COM pression你可以做根据熵)。

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.

编辑:由于z的大小是一个硬限制,需要限制输入至8个字节,并且选择使用64位(或更少)块大小加密技术。 河豚和的三重DES 使用64位数据块,但请记住这些算法没有收到同样严格的审查的 AES

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.

如果你想要的东西很简单,相当不安全的,只是 XOR 你输入一个密钥。

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

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

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