yb
yb
지급대행 Encryption Javascript 버전
import { compactDecrypt, CompactEncrypt } from 'jose';
import { uuidv4 } from 'lib0/random';

const encrypt = async (target: object, securityKey: string) => {
// securityKey is a 64 character Hexadecimal string, change it to a byte array
const key = Buffer.from(securityKey, 'hex');
const keyInUint8Array = new Uint8Array(key);
const payload = JSON.stringify(target);
const payloadAsUint8Array = new TextEncoder().encode(payload);

const encryption = new CompactEncrypt(payloadAsUint8Array);
const encrypted = await encryption
.setProtectedHeader({
alg: 'dir',
enc: 'A256GCM',
iat: new Date().toISOString(),
nonce: uuidv4(),
})
.encrypt(keyInUint8Array);
return encrypted;
};

const decrypt = async (encrypted: string, securityKey: string) => {
const key = Buffer.from(securityKey, 'hex');

const keyInUint8Array = new Uint8Array(key);
const decryption = await compactDecrypt(encrypted, keyInUint8Array);
const plainTextInUint8Array = decryption.plaintext;
// decode the plain text from Uint8Array to string in utf-8
const plainText = new TextDecoder().decode(plainTextInUint8Array);
return JSON.parse(plainText) as object;
};

export { encrypt, decrypt };
import { compactDecrypt, CompactEncrypt } from 'jose';
import { uuidv4 } from 'lib0/random';

const encrypt = async (target: object, securityKey: string) => {
// securityKey is a 64 character Hexadecimal string, change it to a byte array
const key = Buffer.from(securityKey, 'hex');
const keyInUint8Array = new Uint8Array(key);
const payload = JSON.stringify(target);
const payloadAsUint8Array = new TextEncoder().encode(payload);

const encryption = new CompactEncrypt(payloadAsUint8Array);
const encrypted = await encryption
.setProtectedHeader({
alg: 'dir',
enc: 'A256GCM',
iat: new Date().toISOString(),
nonce: uuidv4(),
})
.encrypt(keyInUint8Array);
return encrypted;
};

const decrypt = async (encrypted: string, securityKey: string) => {
const key = Buffer.from(securityKey, 'hex');

const keyInUint8Array = new Uint8Array(key);
const decryption = await compactDecrypt(encrypted, keyInUint8Array);
const plainTextInUint8Array = decryption.plaintext;
// decode the plain text from Uint8Array to string in utf-8
const plainText = new TextDecoder().decode(plainTextInUint8Array);
return JSON.parse(plainText) as object;
};

export { encrypt, decrypt };
Node 환경에서 구현한 간단한 예시입니다 🙂
5 replies
테스트 환경에서 셀러 등록
라이브 버전의 시크릿키와 보안 키로는 셀러 등록(POST /v2/sellers)이 정상적으로 요청되나, 테스트 버전의 시크릿키와 보안 키로 호출 시
{
version: '2022-11-16',
traceId: 'ec3f43ec91c7383dd757f199f3fcf72e',
entityBody: null,
entityType: null,
error: { code: 'FORBIDDEN_REQUEST', message: 'Not allowed request' }
}
{
version: '2022-11-16',
traceId: 'ec3f43ec91c7383dd757f199f3fcf72e',
entityBody: null,
entityType: null,
error: { code: 'FORBIDDEN_REQUEST', message: 'Not allowed request' }
}
아래와 같은 결과를 얻습니다. 혹시 지원하지 않는 기능인가요?
3 replies
테스트 시크릿키와 보안키를 통한 셀러 등록
No description
7 replies