guids的对称映射

本文关键字:映射 对称 guids | 更新日期: 2023-09-27 18:10:24

是否有一个现有的安全实现来实现以下目标:


Guid original = Guid.NewGuid();
Guid inverted = MysteryImplementation(original, salt); // salt is some sort of input
Guid shouldBeOriginal = MysteryImplementation(inverted, salt);
Assert.AreEqual(original, shouldBeOriginal, "MysteryImplementation did no work");

EDIT:

As this got down voted (although I'm a bit unsure why), I think more background is needed:

In a place far far away, there is an application in which primary keys are stored as GUIDs. In this application these GUIDs are exposed to web clients.

In my pursuit of improving status quo I had an idea to map these GUIDs with user session data in order mitigate the risk of an accidental/malicious leakage of primary keys. Mapping these GUIDs has the added benefit that it would also allow easier implementation of working-copies for those objects that the GUIDs refer to.

Those were the reasons why I decided to start looking for "secure" way to map GUIDs.

To answer comments:

-Mapping should preserve the global uniqueness when compared to all other GUIDs (I wouldn't want those mapped GUIDs to collide with existing GUIDs).

-"Secure" in this context means that it should be impossible to figure out the original GUIDs without knowing the cipher key (a typical crypto req, which I think translates that the mapped GUIDs should have normalized distribution).

guids的对称映射

You can easily do this:

Guid original = Guid.NewGuid();
byte[] encrypted = Encrypt(original, key);
Guid decrypted = Decrypt(encrypted, key);

从ROT13起,任何对称编码算法都可以。然而,这不是你想要的。你要求的是一个有两个属性的算法:

  • 加密和解密算法完全相同。
  • GUID的加密形式是也是一个有效的全局唯一标识符

有很多算法的加密和解密过程是不同的,但实际上它们完全相同的算法并不多。加密和解密相同的最简单算法是:

  • 生成与明文长度相同的加密强度随机一次性pad
  • 将明文与pad进行XOR,生成密文。
  • 要解密,用键盘对密文进行异或。

然而该算法并不一定保持密文是有效GUID的属性

你能解释一下为什么你需要密文是一个有效的GUID吗?GUID必须具有的属性是它必须是全局唯一的;你们打算如何保证全球独特性?是什么阻止您将您生成的GUID 加密为其他人在您不知道的情况下生成的另一个GUID ?

更一般地说,你能首先向解释你想要解决的问题吗?十有八九我看到有人试图使用密码学,他们把它用于错误的目的。

是。这些神秘的算法被称为对称密码。你所说的salt就是算法的关键。

然而,它可能有点难得到GUID,因为加密算法通常操作在流或数据块上,通过修改GUID你危及它的GU属性。

任何对称加密都可以

http://msdn.microsoft.com/en-us/library/as0w18af (v = vs.110) . aspx