在C#中的字节数组密码 [英] Byte array cryptography in C#

查看:231
本文介绍了在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天全站免登陆