feat: 支持open api接口,根据域名获取证书

This commit is contained in:
xiaojunnuo
2025-01-14 00:54:30 +08:00
parent c6c269f9e4
commit 52a4fd3318
13 changed files with 294 additions and 32 deletions
@@ -1,2 +1,3 @@
export * from './service/plus-service.js';
export * from './service/file-service.js';
export * from './service/encryptor.js';
@@ -0,0 +1,29 @@
import crypto from 'crypto';
export class Encryptor {
secretKey: Buffer;
constructor(encryptSecret: string) {
this.secretKey = Buffer.from(encryptSecret, 'base64');
}
// 加密函数
encrypt(text: string) {
const iv = crypto.randomBytes(16); // 初始化向量
// const secretKey = crypto.randomBytes(32);
// const key = Buffer.from(secretKey);
const cipher = crypto.createCipheriv('aes-256-cbc', this.secretKey, iv);
let encrypted = cipher.update(text);
encrypted = Buffer.concat([encrypted, cipher.final()]);
return iv.toString('hex') + ':' + encrypted.toString('hex');
}
// 解密函数
decrypt(encryptedText: string) {
const textParts = encryptedText.split(':');
const iv = Buffer.from(textParts.shift(), 'hex');
const encrypted = Buffer.from(textParts.join(':'), 'hex');
const decipher = crypto.createDecipheriv('aes-256-cbc', Buffer.from(this.secretKey), iv);
let decrypted = decipher.update(encrypted);
decrypted = Buffer.concat([decrypted, decipher.final()]);
return decrypted.toString();
}
}