字节数组加密在C# [英] Byte array cryptography in C#

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

问题描述

我想使用按位运算符创建一个不错的加密。
但是我没有这样做。

I want to create a nice cryptography using bitwise operators. However I fail to do so.

我希望它有一个位操作符使用一个字节数组加密和解密我的字节数组。

I want it to have bitwise operators using a byte array to encrypt and decrypt my byte array.

public class Cryptographer
{
    private byte[] Keys { get; set; }

    public Cryptographer(string password)
    {
        Keys = Encoding.ASCII.GetBytes(password);
    }

    public void Encrypt(byte[] data)
    {
        for(int i = 0; i < data.Length; i++)
        {
            data[i] = (byte) (data[i] & Keys[i]);
        }
    }

    public void Decrypt(byte[] data)
    {
        for (int i = 0; i < data.Length; i++)
        {
            data[i] = (byte)(Keys[i] & data[i]);
        }
    }
}



我知道这是错误的,这就是为什么我需要帮助。
我只想使用1个字符串来加密和解密所有数据。

I know this is wrong, thats why I need help. I simply want it to use 1 string to encrypt and decrypt all data.

推荐答案

作为craptography,因为它提供了安全的错觉,而功能上无用的保护任何东西。如果您要进行加密,请使用框架类

This is what is sometimes known as 'craptography', because it provides the illusion of security while being functionally useless in protecting anything. Use the framework classes if you want to do cryptography right, because it's extremely difficult to roll your own.

看看这是关于你想做什么(加密/解密)的建议 - http://msdn.microsoft.com/en-us/library/e970bs09.aspx 。真的你的要求应该决定你决定使用什么类。这有很好的背景: http://msdn.microsoft.com/en-us /library/92f9ye3s.aspx

Take a look at this for advice on what you are trying to do (encrypt/decrypt) - http://msdn.microsoft.com/en-us/library/e970bs09.aspx. Really your requirements should determine what classes you decide to use. This has good background: http://msdn.microsoft.com/en-us/library/92f9ye3s.aspx

对于简单加密/解密(如果这是您需要的) DPAPI 可能是最简单的方法。

For simple encrypt/decrypt (if this is what you need) DPAPI may be the simplest way.

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

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