package com.eactive.eai.common.security.keyderiv.strategy;

import java.util.Map;

import com.eactive.eai.common.security.keyderiv.DerivedKey;

/**
 * HSM 마스터키를 사용하는 전략
 *
 * key_deriv_params (JSON) 예시: { "hsmKeyAlias" : "MASTER_KEY_AES", "hsmIvAlias" : "MASTER_IV_AES"}
 */
public class HsmKeyAndIvDerivationStrategy extends BaseHsmKeyDerivationStrategy {

	@Override
	public DerivedKey deriveKey(Map<String, String> params, Map<String, String> runtimeContext) throws Exception {
		byte[] masterKeyBytes = super.getHsmKey(params);
		byte[] iv = super.getHsmIv(params);
		return new DerivedKey(masterKeyBytes, masterKeyBytes, iv);
	}

	@Override
	public String buildCacheKey(String cryptoName, Map<String, String> params, Map<String, String> runtimeContext) {
		return cryptoName;
	}
}
