Cryptographyでの暗号化

  • タグ:
  • タグはありません
using System;
using System.Text;
using System.Security.Cryptography;
using System.Runtime.InteropServices;

namespace Encryption
{
    [ComVisible(true)]
    public class Crypt : IDisposable
    {
        public string Encrypt(string arg)
        {
            byte[] bytes = Encoding.Unicode.GetBytes(arg);
            byte[] cryptData = ProtectedData.Protect(bytes, null, DataProtectionScope.CurrentUser);
            return ByteArrayToString(protectedData);
        }
        private string ByteArrayToString(byte[] ba)
        {
            string hexStr = BitConverter.ToString(ba);
            return hexStr.Replace("-", "");
        }
        public void Dispose(){}
    }
}