3,143
社区成员
发帖
与我相关
我的任务
分享
var text = crypto.Utf8.parse(String.fromCharCode(0x11, 0x22, 0x33, 0x44, 0x55, 0x66));
console.log('----------------------------------------------------------明文:', text);
var keys = hexMD5(0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12);
var XMD5Keys = crypto.Utf8.parse(this.DEE(keys));
console.log('----------------------------------------------------------密钥:', XMD5Keys);
var iv = hexMD5(0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xef,0xcd,0xab,0x89,0x67,0x45,0x23,0x01);
var EMD5iv = crypto.Utf8.parse(this.DEE(iv));
console.log('----------------------------------------------------------向量:', EMD5iv);
var mi = new crypto.AES().encrypt(text, XMD5Keys, {iv: EMD5iv,mode: crypto.Mode.CFB,padding: crypto.Padding.NoPadding});
console.log('----------------------------------------------------------加密:', this.DEE(mi.ciphertext.toString()));
var v = new crypto.AES().decrypt(mi.toString(), XMD5Keys, {iv: EMD5iv,mode: crypto.Mode.CFB, padding: crypto.Padding.NoPadding});
console.log('----------------------------------------------------------解密:', this.DEE(v.toString()));
var text = crypto.Utf8.parse(String.fromCharCode(0xA5, 0xB1, 0x04, 0x01, 0x00));
var XMD5Keys = crypto.Utf8.parse(this.DEE(hexMD5(this.DEE(2a6938114530))));
var EMD5iv = crypto.Utf8.parse(this.DEE(hexMD5(this.DEE(e6ff6b0257d5de7ea610f219d29feb69))));
var mi = new crypto.AES().encrypt(text, XMD5Keys, { iv: EMD5iv, mode: crypto.Mode.CFB, padding: crypto.Padding.NoPadding });
var mi1 = mi.ciphertext.toString();
var mi2 = mi1.toUpperCase();
console.log('----------------------------------------------------------加密:', this.DEE(mi1));
var v = new crypto.AES().decrypt(mi.toString(), XMD5Keys, {iv:EMD5iv,mode:crypto.Mode.CFB,padding:crypto.Padding.NoPadding});
console.log('----------------------------------------------------------解密:', this.DEE(v.toString()));
var typedArray = new Uint8Array(mi2.match(/[\da-f]{2}/gi).map(function (h) {
return parseInt(h, 16)
}))
var buffer1 = typedArray.buffer
wx.writeBLECharacteristicValue({
deviceId: this.data.deviceId,
serviceId: this.data.service_id,
characteristicId: this.data.characteristics,
value: buffer1,
success: function (res) {
console.log('发送数据:' + '√');
},
})
DEE: function(num) {
var num = num.toUpperCase();
var num = (num || 0).toString();
var result = '';
while(num.length > 2) {
result = ',0x' + num.slice(-2) + result;
num = num.slice(0, num.length - 2);
}
if (num) { result = num + result; }
return '0x' + result;
},