牙叔教程 简单易懂
打印$crypto.encrypt
log($crypto.encrypt.toString());
function (data, key, algorithm, options) { return $crypto._cipher(data, Cipher.ENCRYPT_MODE, key, algorithm, options); }
打印$crypto._cipher
log($crypto._cipher.toString());
function (data, mode, key, algorithm, options) { options = options || {}; let cipher = Cipher.getInstance(algorithm); cipher.init(mode, key.toKeySpec(algorithm)); let os; let isFile = options.output == "file" && options.dest; if (isFile) { os = new java.io.FileOutputStream(options.dest); } else { os = new ByteArrayOutputStream(); } let cos = new CipherOutputStream(os, cipher); $crypto._input(data, options, (bytes, start, length) => { cos.write(bytes, start, length); } ); cos.close(); os.close(); if (!isFile) { let result = os.toByteArray(); return $crypto._output(result, options, "bytes"); } }
第4行是
cipher.init(mode, key.toKeySpec(algorithm));
有2个参数
java中是
var cipher = javax.crypto.Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, key, iv);
有3个参数
第三个参数就是 IV
打印cipher.init
function init() {/* void init(int,java.security.Key,java.security.AlgorithmParameters) void init(int,java.security.Key,java.security.SecureRandom) void init(int,java.security.Key,java.security.spec.AlgorithmParameterSpec) void init(int,java.security.cert.Certificate,java.security.SecureRandom) void init(int,java.security.Key) void init(int,java.security.cert.Certificate) void init(int,java.security.Key,java.security.AlgorithmParameters,java.security.SecureRandom) void init(int,java.security.Key,java.security.spec.AlgorithmParameterSpec,java.security.SecureRandom) */}
init有多个重载 (Overload)方法,
autojs实现了两个参数的方法, 其他方法未实现
测试环境
手机: Mi 11 Pro
Android版本: 12
Autojs版本: 8.8.20
名人名言
思路是最重要的, 其他的百度, bing, stackoverflow, github, 安卓文档, autojs文档, 最后才是群里问问 --- 牙叔教程
声明
部分内容来自网络 本教程仅用于学习, 禁止用于其他用途