Files
certd/packages/libs/lib-server/src/user/access/service/encrypt-service.ts
T

30 lines
673 B
TypeScript
Raw Normal View History

2026-05-12 00:06:02 +08:00
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { Encryptor, SysSecret, SysSettingsService } from '../../../system/index.js';
2024-08-27 13:46:19 +08:00
/**
* 授权
*/
@Provide()
2024-12-23 23:33:13 +08:00
@Scope(ScopeEnum.Singleton)
2024-08-27 13:46:19 +08:00
export class EncryptService {
encryptor: Encryptor;
2024-08-27 13:46:19 +08:00
@Inject()
sysSettingService: SysSettingsService;
async doInit() {
const secret: SysSecret = await this.sysSettingService.getSecret();
this.encryptor = new Encryptor(secret.encryptSecret);
2024-08-27 13:46:19 +08:00
}
// 加密函数
encrypt(text: string) {
return this.encryptor.encrypt(text);
2024-08-27 13:46:19 +08:00
}
// 解密函数
decrypt(encryptedText: string) {
return this.encryptor.decrypt(encryptedText);
2024-08-27 13:46:19 +08:00
}
}