简单的加密 [英] simple encryption

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

问题描述



我正在寻找加密的一些.net示例代码:我不想要任何花哨的东西,没有复杂的第三方组件,复杂的算法,原理的解释,或者;公钥/私钥混淆(似乎所有谷歌都可以提出) - 我只想要一个简单的例子,说明如何加密字符串,然后取回相同的字符串。我在MSDN上找到了一个例子,它涉及编译DLL然后在测试表单中使用它,但是大约每5次抛出一个异常,这对我来说不够好 - 我只需要它很简单。它不需要是对抗硬化的破解者的最先进的防御,主要是因为它不能从阅读它看 - 不是更多。但必须简单并且总是给予相同的回报。


任何人?

解决方案

Beeeeeeeeeeeeves< Be**************@discussions.microsoft.com>写道:

我正在寻找一些关于加密的.net示例代码:我不想要任何花哨的东西,没有复杂的第三方组件和复杂的算法,解释原则,或公钥/私钥混淆(这似乎是所有谷歌都可以提出) - 我只是想要一个简单的例子,说明我如何加密字符串然后得到返回
相同的字符串。我在MSDN上找到了一个例子,它涉及编译一个DLL,然后在测试表单中使用它,但是大约有五分之一它会抛出异常,这对我来说不够好 - 我只需要它很简单。它不需要是对抗强化的黑客攻击者的最先进的防御,主要是因为它不能从瞥见它 - 而不是更多。但必须简单并且总是给予相同的回复。




CryptoStream的文档给出了一个加密字节

数组的简单示例。要使用字符串,只需使用Encoding.UTF8.GetBytes

将字符串转换为字节数组,并将Encoding.UTF8.GetString转换为

,然后在解密后将其转换回来。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复该群组,请不要给我发邮件


干杯快速响应。


但为什么选择UTF8?

以及文档中此示例的任何链接?


" Jon Skeet [C#MVP]"写道:

Beeeeeeeeeeeeves< Be ************** @ discussion.microsoft.com>写道:

我正在寻找一些关于加密的.net示例代码:我不想要任何花哨的东西,没有复杂的第三方组件和复杂的算法,解释原则,或公钥/私钥混淆(这似乎是所有谷歌都可以提出) - 我只是想要一个简单的例子,说明我如何加密字符串然后得到返回
相同的字符串。我在MSDN上找到了一个例子,它涉及编译一个DLL,然后在测试表单中使用它,但是大约有五分之一它会抛出异常,这对我来说不够好 - 我只需要它很简单。它不需要是对抗强化的黑客攻击者的最先进的防御,主要是因为它不能从瞥见它 - 而不是更多。但必须简单并且总是给予相同的回复。



CryptoStream的文档给出了一个加密字节数组的简单示例。要使用字符串,只需使用Encoding.UTF8.GetBytes将字符串转换为字节数组,然后使用Encoding.UTF8.GetString将其解密后再将其转换回来。

- Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复小组,请不要给我发邮件


Beeeeeeeeeeeeves< Be ************** @ discussion.microsoft.com>写道:

为快速回应干杯。

但为什么选择UTF8?


这是一种无损编码,适用于ASCII。如果你使用的是很多非ASCII的,那么使用Encoding.Unicode会有意义。

和文档中这个例子的任何链接?




什么,使用Encoding.UTF8?从来没听说过。加密

从根本上对二进制数据起作用,二进制数据和文本数据之间的转换与加密本身截然不同。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复小组,请不要给我发邮件


Hi
I''m looking for some .net example code on encryption: I don''t want anything fancy, no complex third party components with sophisticated algorithms, explanations of principle, or "public/private key" confusion (which seems to be all google can come up with) - I just want a SIMPLE example of how I can encrypt a string and then get back the SAME STRING. I found an example on MSDN which involves compiling a DLL then using it in a test form, but about 1 in 5 times it throws an exception, this isn''t good enough for me - I just need it to be simple. It doesn''t need to be state of the art defence against hardened crackers, mainly just so it can''t be read from glancing at it - not much more. But must be SIMPLE and ALWAYS GIVE THE SAME THING BACK.

Anyone?

解决方案

Beeeeeeeeeeeeves <Be**************@discussions.microsoft.com> wrote:

I''m looking for some .net example code on encryption: I don''t want
anything fancy, no complex third party components with sophisticated
algorithms, explanations of principle, or "public/private key"
confusion (which seems to be all google can come up with) - I just
want a SIMPLE example of how I can encrypt a string and then get back
the SAME STRING. I found an example on MSDN which involves compiling
a DLL then using it in a test form, but about 1 in 5 times it
throwsan exception, this isn''t good enough for me - I just need it to
be simple. It doesn''t need to be state of the art defence against hardened
crackers, mainly just so it can''t be read from glancing at it - not
much more. But must be SIMPLE and ALWAYS GIVE THE SAME THING BACK.



The docs for CryptoStream give a simple example of encrypting a byte
array. To use strings instead, just use Encoding.UTF8.GetBytes to
transform the string into a byte array, and Encoding.UTF8.GetString to
transform it back after decrypting.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Cheers for the very quick response.

But why UTF8?

And any link to this example in the docs?

"Jon Skeet [C# MVP]" wrote:

Beeeeeeeeeeeeves <Be**************@discussions.microsoft.com> wrote:

I''m looking for some .net example code on encryption: I don''t want
anything fancy, no complex third party components with sophisticated
algorithms, explanations of principle, or "public/private key"
confusion (which seems to be all google can come up with) - I just
want a SIMPLE example of how I can encrypt a string and then get back
the SAME STRING. I found an example on MSDN which involves compiling
a DLL then using it in a test form, but about 1 in 5 times it
throwsan exception, this isn''t good enough for me - I just need it to
be simple. It doesn''t need to be state of the art defence against hardened
crackers, mainly just so it can''t be read from glancing at it - not
much more. But must be SIMPLE and ALWAYS GIVE THE SAME THING BACK.



The docs for CryptoStream give a simple example of encrypting a byte
array. To use strings instead, just use Encoding.UTF8.GetBytes to
transform the string into a byte array, and Encoding.UTF8.GetString to
transform it back after decrypting.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too



Beeeeeeeeeeeeves <Be**************@discussions.microsoft.com> wrote:

Cheers for the very quick response.

But why UTF8?
It''s a lossless encoding which is compact for ASCII. If you''re using a
lot of non-ASCII, it would make sense to use Encoding.Unicode instead.
And any link to this example in the docs?



What, to using Encoding.UTF8? Not that I know of. Encryption
fundamentally acts on binary data, and the conversion between binary
data and text data is quite distinct from encryption itself.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


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

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