C# 不使用密钥的加密算法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/952019/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Encryption algorithms that don't use a key
提问by Blankman
I need a simple encryption algorithm that doesn't use a key.
我需要一个不使用密钥的简单加密算法。
Which ones do you guys recommend?
大家推荐哪些呢?
How about if I use the built in encryption method that forms authentication has? (I forget the method/namespace for it).
如果我使用表单身份验证的内置加密方法怎么样?(我忘记了它的方法/命名空间)。
回答by Welbog
Something outside of the thing being encrypted needs to be used to do encryption, if only because you need that thing to decrypt it later. This external thing is a key. There is no useful encryption without a key. There is only hashing.
需要使用被加密事物之外的东西来进行加密,如果只是因为您以后需要那个东西来解密它。这个外在的东西是一个关键。没有密钥就没有有用的加密。只有散列。
回答by belgariontheking
rot13 uses a key that's already in the algorithm. That's the closest I think you're going to get.
rot13 使用算法中已有的密钥。这是我认为你会得到的最接近的。
回答by Jherico
What you are calling encryption is simply obfuscation. Even then its going to be encryption where the key is embedded in the algorithm. You'll have to provide at least a simple use case for this before you're going to get any kind of reasonable answer.
您所说的加密只是混淆。即便如此,它也将是加密,其中密钥嵌入在算法中。在获得任何合理的答案之前,您必须至少为此提供一个简单的用例。
回答by Michael Petrotta
Every symmetrical encryption scheme has a key. If you're looking for an encryption scheme where you don't manage the key, you might look into the Data Protection API, exposed in .NET (2.0 and above) as the System.Security.Cryptography.ProtectedData class. It provides symmetric encryption of arbitrary data, using the credentials of the machine or (better) the user, as the encryption key.
每个对称加密方案都有一个密钥。如果您正在寻找不管理密钥的加密方案,您可以查看Data Protection API,它在 .NET(2.0 及更高版本)中作为 System.Security.Cryptography.ProtectedData 类公开。它使用机器或(更好)用户的凭据作为加密密钥提供任意数据的对称加密。
byte[] plaintextBytes = GetDataToProtect();
byte[] encodedBytes = ProtectedData.Protect(plaintextBytes
, null
, DataProtectionScope.CurrentUser);
See my other answer herefor more detail.
有关更多详细信息,请参阅我的其他答案here。
回答by Bill the Lizard
The problem with keyless encryption is that once it's broken, it's broken for everyone. Take MicroSoft Script Encoderas an example. Once one person figured out how to reverse the encryption and published it, the encryption was broken for everyone (see comments for details on how this isn't as bad as it sounds in this case).
无密钥加密的问题在于,一旦它被破坏,它就会被所有人破坏。以MicroSoft 脚本编码器为例。一旦有人想出如何反转加密并发布它,每个人的加密就会被破坏(有关这在这种情况下如何不像听起来那么糟糕的详细信息,请参阅评论)。
That being said, you can use any keyed algorithm and keep the key a secret and you'll get the same (bad) effect.
话虽如此,您可以使用任何密钥算法并将密钥保密,您将获得相同的(不良)效果。
回答by David Thornley
Fundamentally, ciphers are a way to let Alice tell something to Bob that Eve can't figure out even if she overhears.
从根本上说,密码是一种让爱丽丝向鲍勃讲述夏娃即使偷听也无法弄清楚的事情的一种方式。
This means that there has to be some way for the ciphertext to distinguish Bob from Eve.
这意味着密文必须有某种方式来区分 Bob 和 Eve。
Usually, this is a key. Nowadays, it can be a symmetric cipher key that Alice gives to Bob and not Eve somehow, or an asymmetric cipher key that Bob broadcasts so that anybody can encrypt a message for him that only he can read (often used as a way to transmit a symmetric cipher key).
通常,这是一个关键。如今,它可以是 Alice 以某种方式提供给 Bob 而不是 Eve 的对称密钥,或者是 Bob 广播的非对称密钥,以便任何人都可以为他加密只有他才能阅读的消息(通常用作传输信息的方式)对称密钥)。
An algorithm can serve as a key, but algorithms are really inconvenient to distribute and keep secret. It's better just to use a standard key.
算法可以作为密钥,但算法确实不方便分发和保密。最好只使用标准密钥。
You could simply obfuscate the plaintext, if you're willing to count on Bob being motivated to read the message and Eve not be. You could do that by zipping a file, for example. Eve couldn't just read it, she'd have to unzip it. This is usually done to prevent Eve from accidentally reading something meant for Bob, on the assumption that Eve is honorable but may make occasional mistakes. The example popping into my mind is the CVS password file; it will prevent a sysadmin from seeing the password at a glance, but it's "the moral equivalent of rot13" if somebody actually wants to read it.
如果您愿意指望 Bob 有动力阅读消息而 Eve 不会,您可以简单地混淆明文。例如,您可以通过压缩文件来做到这一点。Eve 不能只是阅读它,她必须解开它。这样做通常是为了防止 Eve 意外地阅读给 Bob 写的东西,假设 Eve 是可敬的,但可能偶尔会犯错误。我想到的例子是 CVS 密码文件;它会阻止系统管理员一目了然地看到密码,但如果有人真的想阅读它,它就是“道德上的 rot13”。
So, to give you a useful answer, we need to know what you want to use this for. How sensitive is the data? How likely is it to fall into unfriendly hands? Who do you want to be able to read it?
所以,为了给你一个有用的答案,我们需要知道你想用它做什么。数据有多敏感?落入不友好之手的可能性有多大?你希望谁能够阅读它?
BTW, never roll your own cryptography. It's real easy to get something wrong and real hard to notice it. Use standard implementations of standard algorithms.
顺便说一句,永远不要推出自己的密码学。弄错东西真的很容易,要注意到它真的很难。使用标准算法的标准实现。
回答by Arjan Einbu
As an aside to the talks about no key = no encryption...
作为关于无密钥 = 无加密的讨论的旁白...
Maybe what you're really after is automatic and safe key creation and exchange with no user interaction. This can be done by the use of asymmetric encryption, and it works like this:
也许您真正想要的是在没有用户交互的情况下自动和安全地创建和交换密钥。这可以通过使用非对称加密来完成,它的工作原理如下:
Scenario:A needs to send a message to B, and wants to make sure no man-in-the middle can read the message.
场景:A 需要给 B 发送一条消息,并希望确保没有中间人可以读取该消息。
A and B initiate a conversation like this:
A 和 B 发起这样的对话:
- A asks B for B's public key.
- B generates a public/private key pair, and sends the public key to A.
- A uses the public key to encrypt the message, and sends the message.
- B receives the message, and decrypts it with its private key.
- A 向 B 询问 B 的公钥。
- B 生成公钥/私钥对,并将公钥发送给 A。
- A 使用公钥加密消息,并发送消息。
- B 收到消息,并用它的私钥解密。
This works since the message is encrypted with a public key, can only be decrypted with the corresponding private key. So the public key doesn't have to be secret. If man-in-the-middle picks up the public key, he can't use it to decrypt the message.
这是有效的,因为消息是用公钥加密的,只能用相应的私钥解密。所以公钥不必是秘密的。如果中间人拿到了公钥,他就不能用它来解密消息。
You'll probably find tons of information about this if you google for asymmetric encryption...
如果您在谷歌上搜索非对称加密,您可能会找到大量关于此的信息......
回答by chris166
If you're really after obfuscation, you can use the PasswordDeriveBytes class to create a key from a password. Then use the key in e.g. AES.
如果您确实需要混淆,则可以使用 PasswordDeriveBytes 类从密码创建密钥。然后使用例如 AES 中的密钥。