我正在使用iaik pkcs11java试图用RSA公钥包装AES密钥。
有人可以帮助我上面的参数/代码有什么问题吗?
我正在尝试用RSA公钥包装AES密钥。获取机制无效的问题
Mechanism mechanism = Mechanism.get(PKCS11Constants.CKM_RSA_PKCS_OAEP);
RSAPkcsOaepParameters rsaPkcsOaepParameters =
new RSAPkcsOaepParameters(
Mechanism.get(PKCS11Constants.CKM_SHA256),
RSAPkcsParameters.MessageGenerationFunctionType.SHA256,
RSAPkcsOaepParameters.SourceType.EMPTY,
null);
mechanism.setParameters(rsaPkcsOaepParameters);
session.wrapKey(mechanism, wrappingKey, keyToWrap);
一个RSA的公钥句柄和一个AES密钥
iaik.pkcs.pkcs11.wrapper.PKCS11Exception: CKR_MECHANISM_PARAM_INVALID
at iaik.pkcs.pkcs11.wrapper.PKCS11Implementation.C_WrapKey(Native Method) ~[iaik-pkcs11-wrapper-1.6.4.jar:?]
at iaik.pkcs.pkcs11.Session.wrapKey(Session.java:1433) ~[iaik-pkcs11-wrapper-1.6.4.jar:?]
据我所知,您应该使用RSAPkcsOaepParameters. SourceType.DATA_SPECIFIED
(CKZ_DATA_SPECIFIED
在PKCS#11中指定的):
public static Mechanism getRsaOaepSha256Mechanism() {
Mechanism mechanism = Mechanism.get(PKCS11Constants.CKM_RSA_PKCS_OAEP);
RSAPkcsOaepParameters rsaPkcsOaepParameters =
new RSAPkcsOaepParameters(
Mechanism.get(PKCS11Constants.CKM_SHA256),
RSAPkcsParameters.MessageGenerationFunctionType.SHA256,
RSAPkcsOaepParameters.SourceType.DATA_SPECIFIED,
null);
mechanism.setParameters(rsaPkcsOaepParameters);
return mechanism;
}
祝你的项目好运!