[대상향] SAP erp 웹링크용 암호화 모듈 작성.

This commit is contained in:
leejinho 2020-02-24 14:45:53 +09:00
parent 389db64acc
commit 523e4c0811
2 changed files with 53 additions and 1 deletions

View File

@ -49,7 +49,8 @@ import { environment } from '../../../../environments/environment';
import { import {
DaesangApiService, DaesangApiService,
DaesangProtocolService, DaesangProtocolService,
WebLinkType WebLinkType,
DaesangCipherService
} from '@ucap-webmessenger/daesang'; } from '@ucap-webmessenger/daesang';
import { NGXLogger } from 'ngx-logger'; import { NGXLogger } from 'ngx-logger';
import { import {
@ -133,6 +134,7 @@ export class TopBarComponent implements OnInit, OnDestroy {
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService, @Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
private changeDetectorRef: ChangeDetectorRef, private changeDetectorRef: ChangeDetectorRef,
private dialogService: DialogService, private dialogService: DialogService,
private daesangCipherService: DaesangCipherService,
private localStorageService: LocalStorageService, private localStorageService: LocalStorageService,
private sessionStorageService: SessionStorageService, private sessionStorageService: SessionStorageService,
private publicApiService: PublicApiService, private publicApiService: PublicApiService,

View File

@ -1,6 +1,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import CryptoJS from 'crypto-js'; import CryptoJS from 'crypto-js';
import crypto from 'crypto'; import crypto from 'crypto';
import moment from 'moment';
import { CipherUtil } from '../utils/CipherUtil'; import { CipherUtil } from '../utils/CipherUtil';
@ -40,4 +41,53 @@ export class DaesangCipherService {
.toString() .toString()
.toUpperCase(); .toUpperCase();
} }
/**
* Sap of Weblink
* @description
* const enc = this.daesangCipherService.encryptForSapErp('aes256-daesang-key!!',12345678);
* console.log('enc', enc);
* const dec = this.daesangCipherService.decryptForSapErp('aes256-daesang-key!!',enc);
* console.log('dec', dec);
*/
encryptForSapErp(pvUserKey: string, employeeNum: number): string {
// const txt = '20200221090321_asdfghjk'; // 1QgLAiLqJ6Uo6bE4Qk1o3Yd6mfqxXSnmqXX%2FXLL7DoA%3D
// const txt = '20200221101444_asdfghjk'; // Lz1TIdGTQQMui%2BBHMdj8fatYYhXbwJEL%2BJ91C7jUWEs%3D
const str = moment().format('YYYYMMDDHHmmss') + '_' + employeeNum;
const secretKeyToByteArray: Buffer = Buffer.from(pvUserKey, 'utf8').slice(
0,
16
);
const ivParamenter: Buffer = Buffer.from(pvUserKey.slice(0, 16));
const cipher: crypto.Cipher = crypto.createCipheriv(
'aes-128-cbc',
secretKeyToByteArray,
ivParamenter
);
let encryptedValue: string = cipher.update(str, 'utf8', 'base64');
encryptedValue += cipher.final('base64');
return encodeURIComponent(encryptedValue);
}
decryptForSapErp(pvUserKey: string, encryptedValue: string): string {
const secretKeyToByteArray: Buffer = Buffer.from(pvUserKey, 'utf8').slice(
0,
16
);
const ivParamenter: Buffer = Buffer.from(pvUserKey.slice(0, 16));
const cipher: crypto.Decipher = crypto.createDecipheriv(
'aes-128-cbc',
secretKeyToByteArray,
ivParamenter
);
let decryptedValue: string = cipher.update(
decodeURIComponent(encryptedValue),
'base64',
'utf8'
);
decryptedValue += cipher.final('utf8');
return decryptedValue;
}
} }