名称';EncryptStringToBytes_Eas';在当前上下文中不存在

本文关键字:上下文 不存在 Eas EncryptStringToBytes 名称 | 更新日期: 2023-09-27 18:20:26

此处为Windows Phone初学者。

我在Windows Phone AesManaged Class上查看了AES教程,并在我的示例项目中尝试了该示例。

我无法让它工作,它一直给出错误

名称"EncryptStringToBytes_As"在当前上下文

非常感谢您的帮助。


代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace myProject.Services
{
    class Encrypter
    {
        public static string encryptMessage(String message)
        {
            string cryptex = null;
            try
            {
                using (AesManaged theAes = new AesManaged())
                {
                    byte[] encryptedStream = EncryptStringToBytes_Aes(message, theAes.Key, theAes.IV);
                    cryptex = System.Text.Encoding.UTF8.GetString(encryptedStream, 0, encryptedStream.Count());
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error: {0}", ex.Message);
            }
            return cryptex;
        }
    }
}

名称';EncryptStringToBytes_Eas';在当前上下文中不存在

是的,您链接到的页面在示例代码中包括EncryptStringToBytes_Aes方法,但由于某种原因,您在复制它时忽略了它。它只是在Demo方法下。。。

static byte[] EncryptStringToBytes_Aes(string plainText, byte[] Key, byte[] IV)
{
    // Check arguments.
    if (plainText == null || plainText.Length <= 0)
        throw new ArgumentNullException("plainText");
    ...
}