好的,所以我尝试使用加密生成公钥和私钥(https://nodejs.org/api/crypto.html#crypto_crypto_generatekeypair_type_options_callback)
问题是,generateKeyPair 的参数之一是回调函数,我无法让我的代码等待回调运行。它最终会运行,但那时我已经尝试使用这些数据。我们的想法是做这样的事情:
const _getKeyPair = (pwd: string): Object => {
const { generateKeyPair }: any = require('crypto');
const keyPair = { publicKey: '', privateKey: '' };
generateKeyPair('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: pwd
}
}, (err: Error, publicKey: string, privateKey: string) => {
if (err) {
throw err;
}
keyPair.publicKey = publicKey;
keyPair.privateKey = privateKey;
});
return keyPair;
};
Run Code Online (Sandbox Code Playgroud)
并致电:
const keyPair = …Run Code Online (Sandbox Code Playgroud) 我有续集连接。
然后,我创建我需要的每个表(如果它们尚不存在)。然而,在我这样做之前,如果模式不存在,我想创建它本身,这样我就可以在安装了 mysql 的任何地方运行这个脚本,而不必担心。有没有办法用续集来做到这一点?或者如果没有的话使用任何其他工具。