对称传输密钥 (密钥加密密钥)
IBM 公共加密体系结构 (CCA) 具有一个称为密钥分离的功能,在此功能中,它通过将密钥分隔为唯一用法类型来控制密钥的使用,仅允许将特定类型的密钥用于其预期用途。 例如,用于保护数据的密钥不能用于保护密钥。
缺省情况下, IBMJCECCA 提供程序支持对称密钥生成 DATA 加密密钥。 此密钥用法类型是对称密钥中最常用的,用于保护数据隐私。 除了 DATA 加密密钥外, IBMJCECCA 提供程序还能够生成传输密钥,也称为密钥加密密钥。 传输密钥用于在从一个系统到另一个系统的分发期间保护密钥。 IBMJCECCA 提供程序支持以下类型的传输密钥:
- 双长 112 位导出器三重 DES 密钥
- 双长度 112 位 IMPORTER 三重 DES 密钥
- 导出器 AES 密钥的所有长度
- IMPORTER AES 密钥的所有长度
传输密钥可以通过密钥生成器生成,也可以通过 Diffie-Hellman 密钥协议派生。 在这两种情况下,必须使用包含与传输密钥生成或密钥派生相关的加密参数的 AlgorithmParameterSpec 对象来初始化密钥生成器或密钥协议。
在 z/OS®上, CKDS 类型的 AES 传输密钥需要支持可变长度记录的 CKDS。 请参阅 ICSF System Programmer 's Guide 中标题为 Converting a CKDS from fixed length to variable length record format
的部分,以获取更多信息或与系统管理员联系。
通常,使用通过 IBMJCECCA 提供程序生成的传输密钥保护的密钥只能在 IBM Z® 系统之间分发。 由于在 IBM Z 系统上使用控制向量提供了额外的安全性,因此即使使用了正确的 IMPORTER 键,也不太可能在非 IBM Z的系统上正确重构使用 IBM Z 系统上的传输密钥进行保护的密钥。
带有 NoCvKEK三重DES传输密钥可用于与非z系统交换密钥。 带有 NoCvKEK三重DES传输密钥也可用于与z系统交换密钥,但由于NoCvKEK传输密钥不使用控制向量,因此密钥交换的安全性会降低。 在创建或导入三重DES传输密钥时,可以为该密钥指定 NoCvKEK。 CCA密钥存储区中的三重DES传输密钥才能选择 NoCvKEK。
IBMJCECCA 密钥生成器生成 OPEX 格式的传输密钥,该传输密钥由 EXPORTER/IMPORTER 对或IMPORTER/导出器对组成。 OPEX 是指一对密钥,其中第一个密钥采用可操作 (OP) 形式并可供本地系统使用,而第二个密钥采用可导出 (EX) 形式,需要先导入才能在系统上使用。 操作 (OP) 密钥由本地主密钥直接加密,并在 Java™ 中表示为 Key 对象。 另一方面,可导出 (EX) 密钥与 Java 中的打包密钥类似。 可导出 (EX) 密钥由现有操作 (OP) 导出器密钥加密,并在 Java 中表示为字节数组。
有关 IBM 公共加密体系结构 (CCA) 支持的密钥使用类型和密钥表单的详细说明,请参阅 密码服务集成密码服务设施应用程序员指南中标题为 对称密钥的功能
的部分。 请注意,并非 CCA 中提供的所有密钥使用类型和密钥表单都受 IBMJCECCA 提供程序支持。 此外, IBMJCECCA 提供程序仅支持 CCA 中可用的传输密钥功能的一部分。
使用 IBMJCECCA 密钥生成器生成传输密钥需要现有传输密钥。 因此,没有传输密钥的系统不能使用密钥生成器来生成传输密钥。 此类系统的解决方案是使用 IBMJCECCA 的 Diffie-Hellman 密钥协议函数来派生其初始传输密钥。
在使用椭圆曲线键的两方 Diffie-Hellman 键协议方案中,这是 IBMJCECCA 提供程序当前支持的唯一类型的 Diffie-Hellman 键协议,其中一个系统派生操作 (OP) 导出器键,而另一个系统派生匹配操作 (OP) IMPORTER 键。 通过密钥协议派生的密钥都是操作密钥,因此在这种情况下不需要现有传输密钥。 有关使用椭圆曲线键的 Diffie-Hellman 密钥协议的更多信息,请参阅 EC 操作。
使用 IBMJCECCA KeyGenerator 类的实例生成三重 DES 或 AES 传输密钥时,密钥生成器返回的 com.ibm.crypto.hdwrCCA.provider.DESedeKey 或 com.ibm.crypto.hdwrCCA.provider.AESKey 对象表示 OPEX 密钥配对中的操作 (OP) 密钥。 此操作密钥与任何其他 Java 密钥一样,可以直接在系统上使用。
但是,密钥生成器生成的匹配可导出 (EX) 密钥不是 Java 密钥对象,不能直接在系统上使用。 与使用加密密码打包的其他密钥类似,它采用外部密钥令牌格式以导出到另一个系统,并在 Java 中表示为字节数组。 从密钥生成器返回时,可以通过对返回的操作 (OP) 密钥调用 getPairedExternalToken() 公用方法来检索此匹配的可导出 (EX) 密钥令牌。 然后,可以在另一个系统上导入或解包密钥令牌,以创建等效的可操作 Java 密钥对象。
虽然 IBMJCECCA 密钥生成器将生成的可导出 (EX) 密钥令牌存储在表示操作 (OP) 密钥的返回 Java 密钥对象中,但可导出 (EX) 密钥不视为操作 (OP) 密钥的一部分。 因此,在重构操作 (OP) 密钥时,表示存储在返回的操作 (OP) Java 密钥对象中的可导出 (EX) 密钥的密钥令牌值不会持久存在,无论是通过使用操作 (OP) 密钥的密钥规范的 SecretKeyFactory 实例,还是通过使用加密密码对操作密钥 (OP) 进行打包和解包。 对重构的操作 (OP) 键调用 getPairedExternalToken() 方法将返回 null。 应在密钥生成器生成可导出 (EX) 密钥后立即检索其外部密钥令牌。
生成对称传输密钥
// use CCAAlgorithmParameterSpec to specify key size of 168
//
CCAAlgorithmParameterSpec ccaAlgParmSpec = new CCAAlgorithmParameterSpec(168);
// request that an operational DATA key is to be generated
//
ccaAlgParmSpec.setKeyUsage(KeyUsage.OP_DATA);
KeyGenerator keyGenerator = KeyGenerator.getInstance("DESede", "IBMJCECCA");
keyGenerator.init(ccaAlgParmSpec, null);
// this key object represents the generated operational (OP) DATA key
//
SecretKey tdesDataKey = keyGenerator.generateKey();tdesPrimaryExporter的现有三重 DES 导出器密钥下加密的硬件密钥令牌:// use CCAAlgorithmParameterSpec to specify key size of 112
//
CCAAlgorithmParameterSpec ccaAlgParmSpec = new CCAAlgorithmParameterSpec(112);
// request that a transport key pair is to be generated
// first key is an operational (OP) EXPORTER key
// second key is an exportable (EX) IMPORTER key
//
ccaAlgParmSpec.setKeyUsage(KeyUsage.OPEX_EXPORTER_IMPORTER);
// specify an existing triple DES EXPORTER key to be used for
// enciphering the generated IMPORTER key
//
ccaAlgParmSpec.setKey2KeyEncryptingKey(tdesPrimaryExporter);
KeyGenerator keyGenerator = KeyGenerator.getInstance("DESede", "IBMJCECCA");
keyGenerator.init(ccaAlgParmSpec, null);
// this key object represents the generated operational (OP) EXPORTER key
//
DESedeKey tdesExporterKey = (com.ibm.crypto.hdwrCCA.provider.DESedeKey) keyGenerator.generateKey();
// this is the exportable (EX) IMPORTER hardware key token, which is
// enciphered (wrapped) under an existing triple DES EXPORTER key named tdesPrimaryExporter
//
byte[] tdesImporterToken = tdesExporterKey.getPairedExternalToken();tdesPrimaryExporter:// use CCAAlgorithmParameterSpec to specify key size of 112, in
// addition, specify that the generated operational key is to be stored
// in the CCA key storage area
//
CCAAlgorithmParameterSpec ccaAlgParmSpec = new CCAAlgorithmParameterSpec(
112, CCAAlgorithmParameterSpec.CKDS);
// request that a transport key pair is to be generated
// first key is an operational (OP) IMPORTER key
// second key is an exportable (EX) EXPORTER key
//
ccaAlgParmSpec.setKeyUsage(KeyUsage.OPEX_IMPORTER_EXPORTER);
// specify an existing triple DES EXPORTER key to be used for
// enciphering the generated EXPORTER key
//
ccaAlgParmSpec.setKey2KeyEncryptingKey(tdesPrimaryExporter);
KeyGenerator keyGenerator = KeyGenerator.getInstance("DESede", "IBMJCECCA");
keyGenerator.init(ccaAlgParmSpec, null);
// this key object represents the generated operational (OP) IMPORTER
// key, and contains a label for the corresponding CCA key storage area entry
//
DESedeKey tdesImporterKey = (com.ibm.crypto.hdwrCCA.provider.DESedeKey) keyGenerator.generateKey();
// this is the exportable (EX) EXPORTER hardware key token, which is
// enciphered under an existing triple DES EXPORTER key named tdesPrimaryExporter
//
byte[] tdesExporterToken = tdesImporterKey.getPairedExternalToken();// use CCAAlgorithmParameterSpec to specify key size of 192
//
CCAAlgorithmParameterSpec ccaAlgParmSpec = new CCAAlgorithmParameterSpec(192);
// request that an operational DATA key is to be generated
//
ccaAlgParmSpec.setKeyUsage(KeyUsage.OP_DATA);
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES", "IBMJCECCA");
keyGenerator.init(ccaAlgParmSpec, null);
// this key object represents the generated operational (OP) DATA key
//
SecretKey aesDataKey = keyGenerator.generateKey();aesPrimaryExporter的现有 AES 导出器密钥下加密的硬件密钥令牌:// use CCAAlgorithmParameterSpec to specify key size of 256
//
CCAAlgorithmParameterSpec ccaAlgParmSpec = new CCAAlgorithmParameterSpec(256);
// request that a transport key pair is to be generated
// first key is an operational (OP) EXPORTER key
// second key is an exportable (EX) IMPORTER key
//
ccaAlgParmSpec.setKeyUsage(KeyUsage.OPEX_EXPORTER_IMPORTER);
// specify an existing AES EXPORTER key to be used for
// enciphering the generated IMPORTER key
//
ccaAlgParmSpec.setKey2KeyEncryptingKey(aesPrimaryExporter);
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES", "IBMJCECCA");
keyGenerator.init(ccaAlgParmSpec, null);
// this key object represents the generated operational (OP) EXPORTER key
//
AESKey aesExporterKey = (com.ibm.crypto.hdwrCCA.provider.AESKey) keyGenerator.generateKey();
// this is the exportable (EX) IMPORTER hardware key token, which is
// enciphered (wrapped) under an existing AES EXPORTER key named aesPrimaryExporter
//
byte[] aesImporterToken = aesExporterKey.getPairedExternalToken();aesPrimaryExporter:// use CCAAlgorithmParameterSpec to specify key size of 128, in
// addition, specify that the generated operational key is to be stored
// in the CCA key storage area
//
CCAAlgorithmParameterSpec ccaAlgParmSpec = new CCAAlgorithmParameterSpec(
128, CCAAlgorithmParameterSpec.CKDS);
// request that a transport key pair is to be generated
// first key is an operational (OP) IMPORTER key
// second key is an exportable (EX) EXPORTER key
//
ccaAlgParmSpec.setKeyUsage(KeyUsage.OPEX_IMPORTER_EXPORTER);
// specify an existing AES EXPORTER key to be used for
// enciphering the generated EXPORTER key
//
ccaAlgParmSpec.setKey2KeyEncryptingKey(aesPrimaryExporter);
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES", "IBMJCECCA");
keyGenerator.init(ccaAlgParmSpec, null);
// this key object represents the generated operational (OP) IMPORTER
// key, and contains a label for the corresponding CCA key storage area entry
//
AESKey aesImporterKey = (com.ibm.crypto.hdwrCCA.provider.AESKey) keyGenerator.generateKey();
// this is the exportable (EX) EXPORTER hardware key token, which is
// enciphered under an existing AES EXPORTER key named aesPrimaryExporter
//
byte[] aesExporterToken = aesImporterKey.getPairedExternalToken();NoCvKEK生成对称传输密钥
tdesPrimaryExporter 的现有三重DES EXPORTER密钥进行加密:// Use CCAAlgorithmParameterSpec to specify key size of 112 and that
// the generated operational key is to be stored in the CCA key storage area.
// Only a Triple DES transport key in the CCA key storage area can have the NoCvKEK
// option enabled.
//
CCAAlgorithmParameterSpec ccaAlgParmSpec = new CCAAlgorithmParameterSpec(
112, CCAAlgorithmParameterSpec.CKDS);
// request that a transport key pair is to be generated
// first key is an operational (OP) EXPORTER key
// second key is an exportable (EX) IMPORTER key
//
ccaAlgParmSpec.setKeyUsage(KeyUsage.OPEX_EXPORTER_IMPORTER);
// request that the operational (OP) EXPORTER key have
// the NoCvKEK option
//
ccaAlgParmSpec.setNoCvKEK(true);
// specify an existing triple DES EXPORTER key to be used for
// enciphering the generated IMPORTER key
//
ccaAlgParmSpec.setKey2KeyEncryptingKey(tdesPrimaryExporter);
KeyGenerator keyGenerator = KeyGenerator.getInstance("DESede", "IBMJCECCA");
keyGenerator.init(ccaAlgParmSpec, null);
// This key object represents the generated operational (OP) EXPORTER key.
// Because the NoCvKEK option was specified when it was created,
// it is suitable for exchanging keys with non-z systems.
//
DESedeKey tdesExporterKey = (com.ibm.crypto.hdwrCCA.provider.DESedeKey) keyGenerator.generateKey();
// this is the exportable (EX) IMPORTER hardware key token, which is
// enciphered (wrapped) under an existing triple DES EXPORTER key named tdesPrimaryExporter
//
byte[] tdesImporterToken = tdesExporterKey.getPairedExternalToken();tdesPrimaryExporter 的现有三重DES导出密钥进行加密:// Use CCAAlgorithmParameterSpec to specify key size of 112 and that
// the generated operational key is to be stored in the CCA key storage area.
// Only a Triple DES transport key in the CCA key storage area can have the NoCvKEK
// option enabled.
//
CCAAlgorithmParameterSpec ccaAlgParmSpec = new CCAAlgorithmParameterSpec(
112, CCAAlgorithmParameterSpec.CKDS);
// request that a transport key pair is to be generated
// first key is an operational (OP) IMPORTER key
// second key is an exportable (EX) EXPORTER key
//
ccaAlgParmSpec.setKeyUsage(KeyUsage.OPEX_IMPORTER_EXPORTER);
// request that the operational (OP) IMPORTER key have
// the NoCvKEK option
//
ccaAlgParmSpec.setNoCvKEK(true);
// specify an existing triple DES EXPORTER key to be used for
// enciphering the generated EXPORTER key
//
ccaAlgParmSpec.setKey2KeyEncryptingKey(tdesPrimaryExporter);
KeyGenerator keyGenerator = KeyGenerator.getInstance("DESede", "IBMJCECCA");
keyGenerator.init(ccaAlgParmSpec, null);
// This key object represents the generated operational (OP) IMPORTER
// key, and contains a label for the corresponding CCA key storage area entry.
// Because the NoCvKEK option was specified when it was created,
// it is suitable for exchanging keys with non-z systems.
//
DESedeKey tdesImporterKey = (com.ibm.crypto.hdwrCCA.provider.DESedeKey) keyGenerator.generateKey();
// this is the exportable (EX) EXPORTER hardware key token, which is
// enciphered under an existing triple DES EXPORTER key named tdesPrimaryExporter
//
byte[] tdesExporterToken = tdesImporterKey.getPairedExternalToken();