您好,登錄后才能下訂單哦!
這篇文章主要介紹了nodejs如何實現釘釘ISV接入的加密解密方法,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
解密方法
exports.decryptMsg = function (text) { var aes_msg_buffer = new Buffer(text, 'base64'); var key = new Buffer(aes_key + "=", 'base64'); var iv = key.slice(0, 16); var decipher = crypto.createDecipheriv('aes-256-cbc', key, iv); var dec = decipher.write(aes_msg_buffer); dec = decipher.read(); var msg_leng_buffer = dec.slice(16, 20); var msg_length = msg_leng_buffer.readInt32BE(); var rand_buffer = dec.slice(20, 20 + msg_length); var msg = rand_buffer.toString("utf-8"); var result = JSON.parse(msg); return result; };
加密方法
exports.encrypt_text = function (text, aes_key, suiteKey) { var key = new Buffer(aes_key + "=", 'base64'); var iv = key.slice(0, 16); var random_buffer = new Buffer(exports.getRandomStr(16), 'utf-8'); var buffer = new Buffer(text, 'utf-8'); var length_buffer = new Buffer(4); length_buffer.writeUInt32BE(buffer.length, 0); var corpidBytes = new Buffer(suiteKey, 'utf-8'); var newBuffer = Buffer.concat([random_buffer, length_buffer, buffer, corpidBytes]); var cipher = crypto.createCipheriv('aes-256-cbc', key, iv); //cipher.write(newBuffer); //var dec = cipher.read(); var cipheredMsg = Buffer.concat([cipher.update(/*encoded*/newBuffer), cipher.final()]); return cipheredMsg.toString('base64'); };
簽名方法
var arr =[token, timestamp, nonce, res_encrypt] //token 是配置釘釘套件的token,timestamp時間戳, nonce隨機字符串, res_encrypt是上面加密后的結果 exports.signature_arr = function (arr) { arr.sort(); var str = ""; for (var i = 0; i < arr.length; i++) { str += arr[i]; } var sha1 = crypto.createHash('sha1'); sha1.update(str); var msg_signature = sha1.digest('hex'); return msg_signature; };
感謝你能夠認真閱讀完這篇文章,希望小編分享的“nodejs如何實現釘釘ISV接入的加密解密方法”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關注億速云行業資訊頻道,更多相關知識等著你來學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。