nest.js jsencrypt does not work with error `window is not defined`
export class ClientDecryptAuthGuard implements CanActivate {
constructor() {}
async decrypt(req) {
const JSEncrypt = (await import('jsencrypt')).default;
const rsa = new JSEncrypt();
rsa.setPrivateKey(keys.rsaPrivKey);
const token = rsa.decrypt(req.token);
const bodyOriginJson = CryptoJS.AES.decrypt(
req.body['data'],
token.toString(),
).toString(CryptoJS.enc.Utf8);
return [bodyOriginJson, token];
}
async canActivate(context: ExecutionContext): Promise<boolean> {
const req: Request = context.switchToHttp().getRequest();
[req.body, req['token']] = await this.decrypt(req);
const data = req.body;
return true;
}
}
ReferenceError: window is not defined
at Object.
using jsencrypt with nest js guard.
well, u can use node-rsa to decrypt, see here
Try to use 3.4.0