有奖捉虫:行业应用 & 管理与支持文档专题 HOT
PTS 脚本压测模式除了支持原生 JavaScript ES6 语法、以及 ptspts/http 等 pts 开头的包外,也支持从远端加载远程 HTTP(S) 模块。 压测引擎启动时,将下载三方脚本及其依赖信息,并执行用户脚本。
说明
引入的包应当足够的轻量,确保压测脚本能够顺利执行。
PTS 不是 NodeJS,所以三方脚本中加载 NodeJS 库不会生效。
不支持 TypeScript 语法。
不支持浏览器中的函数,例如:setTimeout,XMLRequest 等。

常用搜索远程模块的网站

请单击 模块网站

常用远程模块

crypto

请参考 相关文档
import crypto from 'https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.js'

export default function () {
console.log(crypto.MD5('Message')); // 4c2a8fe7eaf24721cc7a9f0175115bd4
console.log(crypto.SHA1('Message')); // 68f4145fee7dde76afceb910165924ad14cf0d00
console.log(crypto.SHA256('Message')); // 2f77668a9dfbf8d5848b9eeb4a7145ca94c6ed9236e4a773f6dcafa5132b2f91
console.log(crypto.SHA512('Message')); // 4fb472dfc43def7a46ad442c58ac532f89e0c8a96f23b672f5fd637652eab158d4d589444ef7530a34e6626b40830b4e1ec5364611ae31c599bffa958e8b4c4e
console.log(crypto.SHA384('Message')); // b526d8394134b853bd071719bc99d42b669bc9252baa82dcafabc1f322a3841c57cc0c82f080fd331b1666112b27a329
console.log(crypto.RIPEMD160('Message')); // 85eab2fe4383a869da13d51f4b91506924b1f821

console.log(crypto.HmacMD5('Message', 'Secret Passphrase')); // 5e03d0c1b42ef0b7e61fb333f3993949
console.log(crypto.HmacSHA1('Message', 'Secret Passphrase')); // e90f713295ea4cc06c92c9248696ffafc5d01faf
console.log(crypto.HmacSHA256('Message', 'Secret Passphrase')); // 32c647602ab4c4c7543e9c50ae25e567c3354e1532b11649ce308e6e2568d205
console.log(crypto.HmacSHA512('Message', 'Secret Passphrase')); // c03f82cd6f9d03920d95caeedfa722d4e42325a18b049942ee5560787ad2aa394be6b95849c563ecdd37495726cd6236529a721b563b9778dd6119939bcab7e1
console.log(crypto.HmacSHA384('Message', 'Secret Passphrase')); // 84b318cc0232a370c1f8b8746afcb575fc2debc680122c7422fd425638896d0dcf9e905b8cd9c1d7aed8d5439a2a2328
console.log(crypto.HmacRIPEMD160('Message', 'Secret Passphrase')); // d1b4088aba7f4897444c1423c0b1f056605473ab

let words = crypto.enc.Base64.parse('SGVsbG8sIFdvcmxkIQ==');
console.log(words); // 48656c6c6f2c20576f726c6421

let base64 = crypto.enc.Base64.stringify(words);
console.log(base64); // SGVsbG8sIFdvcmxkIQ==

words = crypto.enc.Latin1.parse('Hello, World!');
console.log(words); // 48656c6c6f2c20576f726c6421

let latin1 = crypto.enc.Latin1.stringify(words);
console.log(latin1); // Hello, World!

words = crypto.enc.Hex.parse('48656c6c6f2c20576f726c6421');
console.log(words); // 48656c6c6f2c20576f726c6421

let hex = crypto.enc.Hex.stringify(words);
console.log(hex); // 48656c6c6f2c20576f726c6421

words = crypto.enc.Utf8.parse('?');
console.log(words); // f094ada2

let utf8 = crypto.enc.Utf8.stringify(words);
console.log(utf8); // ?

words = crypto.enc.Utf16.parse('Hello, World!');
console.log(words); // 00480065006c006c006f002c00200057006f0072006c00640021

let utf16 = crypto.enc.Utf16.stringify(words);
console.log(utf16); // Hello, World!

words = crypto.enc.Utf16LE.parse('Hello, World!');
console.log(words); // 480065006c006c006f002c00200057006f0072006c0064002100

utf16 = crypto.enc.Utf16LE.stringify(words);
console.log(utf16); // Hello, World!
}

aes

请参考 相关文档
import aesjs from 'https://cdnjs.cloudflare.com/ajax/libs/aes-js/4.0.0-beta.2/index.js'

export default function () {
// An example 128-bit key (16 bytes * 8 bits/byte = 128 bits)
var key = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];

// Convert text to bytes
var text = 'Text may be any length you wish, no padding is required.';
var textBytes = aesjs.utils.utf8.toBytes(text);

// The counter is optional, and if omitted will begin at 1
var aesCtr = new aesjs.ModeOfOperation.ctr(key, new aesjs.Counter(5));
var encryptedBytes = aesCtr.encrypt(textBytes);

// To print or store the binary data, you may convert it to hex
var encryptedHex = aesjs.utils.hex.fromBytes(encryptedBytes);
console.log(encryptedHex);
// "a338eda3874ed884b6199150d36f49988c90f5c47fe7792b0cf8c7f77eeffd87
// ea145b73e82aefcf2076f881c88879e4e25b1d7b24ba2788"

// When ready to decrypt the hex string, convert it back to bytes
var encryptedBytes = aesjs.utils.hex.toBytes(encryptedHex);

// The counter mode of operation maintains internal state, so to
// decrypt a new instance must be instantiated.
var aesCtr = new aesjs.ModeOfOperation.ctr(key, new aesjs.Counter(5));
var decryptedBytes = aesCtr.decrypt(encryptedBytes);

// Convert our bytes back into text
var decryptedText = aesjs.utils.utf8.fromBytes(decryptedBytes);
console.log(decryptedText);
// "Text may be any length you wish, no padding is required."
}