Skip to content

Commit

Permalink
Merge pull request #45 from PBTP/bugfix/security
Browse files Browse the repository at this point in the history
bugfix: decrypt nullable 처리
  • Loading branch information
emibgo2 authored Oct 16, 2024
2 parents 5e41d1b + 44cfe11 commit 67bfe18
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
11 changes: 8 additions & 3 deletions src/auth/application/security.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from "@nestjs/common";
import * as crypto from "crypto";
import { ConfigService } from "@nestjs/config";
import { Injectable } from '@nestjs/common';
import * as crypto from 'crypto';
import { ConfigService } from '@nestjs/config';

@Injectable()
export class SecurityService {
Expand Down Expand Up @@ -29,6 +29,11 @@ export class SecurityService {
if (!hash) return null;

const [iv, encryptedText] = hash.split(':');

if (!iv || !encryptedText) {
return null;
}

const decipher = crypto.createDecipheriv(
this.algorithm,
this.secretKey,
Expand Down
25 changes: 13 additions & 12 deletions src/customer/application/customer.service.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Injectable, Logger } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { Repository } from "typeorm";
import { Customer } from "../../schemas/customer.entity";
import { CustomerDto } from "../presentation/customer.dto";
import { IUserService } from "../../auth/user.interface";
import { AuthDto } from "../../auth/presentation/auth.dto";
import { UserDto, UserType } from "../../auth/presentation/user.dto";
import { SecurityService } from "../../auth/application/security.service";
import { Image } from "../../schemas/image.entity";
import { ImageService } from "../../common/image/application/image.service";
import { toDto } from "../../common/function/util.function";
import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Customer } from '../../schemas/customer.entity';
import { CustomerDto } from '../presentation/customer.dto';
import { IUserService } from '../../auth/user.interface';
import { AuthDto } from '../../auth/presentation/auth.dto';
import { UserDto, UserType } from '../../auth/presentation/user.dto';
import { SecurityService } from '../../auth/application/security.service';
import { Image } from '../../schemas/image.entity';
import { ImageService } from '../../common/image/application/image.service';
import { toDto } from '../../common/function/util.function';

@Injectable()
export class CustomerService implements IUserService {
Expand Down Expand Up @@ -61,6 +61,7 @@ export class CustomerService implements IUserService {
customer.customerAddress = this.securityService.decrypt(
customer.customerAddress,
);

customer.customerDetailAddress = this.securityService.decrypt(
customer.customerDetailAddress,
);
Expand Down

0 comments on commit 67bfe18

Please sign in to comment.