小编FaH*_*HaD的帖子

错误:指定的密钥不是此算法的有效大小

我坚持使用加密方法。我对加密或字节数组的了解不多,所以我很难解决这个问题。

这是我的代码:

 public static class EncryptDecrypt {
    private static byte[] key = { };
    private static string sEncryptionKey = "B@|@j!";
    private static byte[] IV = {0x12, 0x34, 0x56, 0x78, 0x90, 0xab};

public static string Encrypt(string stringToEncrypt)
    {
        string returnstring = "";
        try
        {

            key = System.Text.Encoding.UTF8.GetBytes(sEncryptionKey);
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            byte[] inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt);
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            CryptoStream cs = new CryptoStream(ms,
                des.CreateEncryptor(key, IV), CryptoStreamMode.Write);
            cs.Write(inputByteArray, 0, inputByteArray.Length);
            cs.FlushFinalBlock();

            returnstring = Convert.ToBase64String(ms.ToArray());

            //URL Encryption Avoid Reserved Characters …
Run Code Online (Sandbox Code Playgroud)

c# encryption algorithm

1
推荐指数
1
解决办法
6140
查看次数

如何根据C#中的条件使用Linq或Lambda获取Id(int)?

让我们考虑以下数据表:

Id      Name     PhoneNo
1       Sam      123654
2       Mike     213654
3       John     998745
Run Code Online (Sandbox Code Playgroud)

我需要来自此数据列表的Mike的Id并返回int值.我使用AllTestViews方法从数据库中检索所有这些数据作为项目列表.

  int id= gateway.AllTestViews().//Something//(a => a.TestName=="Mike")
    return id;
Run Code Online (Sandbox Code Playgroud)

有没有办法获得此ID或我必须使用SQL查询此问题?谢谢

c# linq lambda

0
推荐指数
2
解决办法
452
查看次数

标签 统计

c# ×2

algorithm ×1

encryption ×1

lambda ×1

linq ×1