Skip to content

Commit

Permalink
Merge pull request #311 from boostcampwm2023/server/fix/293
Browse files Browse the repository at this point in the history
Crypto 모듈 사용 부분 코드 수정
  • Loading branch information
sk000801 authored Dec 7, 2023
2 parents fc695db + 68ac502 commit 1b36162
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions server/src/config/ncloud.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import * as AWS from 'aws-sdk';
import CryptoJS from 'crypto-js';
import { HmacSHA256, enc } from 'crypto-js';
import { getTimeStamp } from 'src/constants';

@Injectable()
Expand Down Expand Up @@ -39,22 +39,18 @@ export class NcloudConfigService {
}

makeSignature(): string {
const hmac = CryptoJS.algo.HMAC.create(
CryptoJS.algo.SHA256,
this.secretKey,
);
const method = 'POST';
const blank = ' ';
const url = this.requestActionsUrl;
const line = '\n';
const timestamp = this.timestamp;
const accessKey = this.accessKey;

hmac.update('POST');
hmac.update(' ');
hmac.update(this.requestActionsUrl);
hmac.update('\n');
hmac.update(this.timestamp);
hmac.update('\n');
hmac.update(this.accessKey);
const message = `${method}${blank}${url}${line}${timestamp}${line}${accessKey}`;

const hash = hmac.finalize();
const hmac = HmacSHA256(message, this.secretKey);

return hash.toString(CryptoJS.enc.Base64);
return enc.Base64.stringify(hmac);
}

getExecuteActionsUrl(): string {
Expand Down

0 comments on commit 1b36162

Please sign in to comment.