• 大小: 4.31MB
    文件类型: .7z
    金币: 1
    下载: 0 次
    发布日期: 2023-11-09
  • 语言: C#
  • 标签: C#  BLE  

资源简介

确认设备管理器蓝牙,有蓝牙 LE 枚举器,管理员运行,选择工具,里面的 BLECODE,尝试连接。发现设备可能会持续一分钟。上一个打包错了,灰常抱歉。

资源截图

代码片段和文件信息

using Microsoft.Office.Interop.Excel;
using NPOI.SS.UserModel;
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace 小田的工具箱
{
    public partial class AES : Form
    {
        public AES()
        {
            InitializeComponent();
        }

        private void AES_Load(object sender EventArgs e)
        {
            comboBox1.Items.Add(“AES-ECB-128-PKCS7“);
            comboBox1.SelectedIndex = 0;
            textBox2.Text = “1234567890123456“;
        }


        public static string Decrypt(string toDecrypt string key)
        {
            byte[] keyArray = System.Text.Encoding.Default.GetBytes(key);//UTF8Encoding.UTF8.GetBytes(key);
            byte[] toEncryptArray = HexStringToByteArray(toDecrypt); //Convert.Frombase64String(toDecrypt);

            RijndaelManaged rDel = new RijndaelManaged();
            rDel.Key = keyArray;
            rDel.Mode = CipherMode.ECB;
            rDel.Padding = PaddingMode.PKCS7;

            ICryptoTransform cTransform = rDel.CreateDecryptor();
            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray 0 toEncryptArray.Length);

            return ByteArrayToHexString(resultArray);//UTF8Encoding.UTF8.GetString(resultArray);
        }

        public static string Encrypt(string toDecrypt string key)
        {
            byte[] keyArray = System.Text.Encoding.Default.GetBytes(key);//UTF8Encoding.UTF8.GetBytes(key);
            byte[] toEncryptArray = null; //Convert.Frombase64String(toDecrypt);
            byte[] resultArray = null;
            try
            {
                toEncryptArray = HexStringToByteArray(toDecrypt);
            }
            catch
            {
                toEncryptArray = Encoding.UTF8.GetBytes(toDecrypt);
            }

            RijndaelManaged rDel = new RijndaelManaged();
            rDel.Key = keyArray;
            rDel.Mode = CipherMode.ECB;
            rDel.Padding = PaddingMode.PKCS7;

            ICryptoTransform cTransform = rDel.CreateEncryptor();
            using (MemoryStream outputStream = new MemoryStream())
            {
                using (CryptoStream inputStream = new CryptoStream(outputStream cTransform CryptoStreamMode.Write))
                {
                    inputStream.Write(toEncryptArray 0 toEncryptArray.Length);
                    inputStream.FlushFinalBlock();
                    resultArray = outputStream.ToArray();
                }

            }
            return ByteArrayToHexString(resultArray);
        }

        public static byte[] HexStringToByteArray(string s)
        {
            s = s.Replace(“ “ ““);
            byte[] buffer = new byte[s.Length / 2];
            for (int i = 0; i < s.Length; i += 2)
            {
                buffer[i / 2] = (byte)Convert.ToByte(s.Substring(i 2) 16);
            }

      

评论

共有 条评论