2019-12-15 18:07:25 +09:00
|
|
|
import { Injectable } from '@angular/core';
|
2019-12-19 08:49:06 +09:00
|
|
|
import CryptoJS from 'crypto-js';
|
2019-12-15 18:07:25 +09:00
|
|
|
import crypto from 'crypto';
|
|
|
|
|
|
|
|
import { CipherUtil } from '../utils/CipherUtil';
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class DaesangCipherService {
|
|
|
|
constructor() {}
|
|
|
|
|
|
|
|
encrypt(pvUserKey: string, pvSource: string, isBase64: string): string {
|
|
|
|
const cipherKeyDTD = CipherUtil.makeCipherKey('AES', pvUserKey);
|
|
|
|
|
|
|
|
const cipher = crypto.createCipheriv(
|
|
|
|
'aes-128-cbc',
|
|
|
|
cipherKeyDTD.key,
|
|
|
|
cipherKeyDTD.iv
|
|
|
|
);
|
|
|
|
cipher.setAutoPadding(true);
|
|
|
|
|
|
|
|
let outputEncoding: 'base64' | 'hex';
|
|
|
|
|
|
|
|
if ('Y' === isBase64) {
|
|
|
|
outputEncoding = 'base64';
|
|
|
|
} else {
|
|
|
|
outputEncoding = 'hex';
|
|
|
|
}
|
|
|
|
|
|
|
|
const cipherChunks = [];
|
|
|
|
cipherChunks.push(cipher.update(pvSource, 'utf8', outputEncoding));
|
|
|
|
cipherChunks.push(cipher.final(outputEncoding));
|
|
|
|
|
|
|
|
return cipherChunks.join('');
|
|
|
|
}
|
2019-12-19 08:49:06 +09:00
|
|
|
|
|
|
|
encryptForWebLink(pvSource: string): string {
|
|
|
|
return CryptoJS.SHA1(pvSource)
|
|
|
|
.toString()
|
|
|
|
.toUpperCase();
|
|
|
|
}
|
2019-12-15 18:07:25 +09:00
|
|
|
}
|