本文整理汇总了Java中java.security.Signature.setParameter方法的典型用法代码示例。如果您正苦于以下问题:Java Signature.setParameter方法的具体用法?Java Signature.setParameter怎么用?Java Signature.setParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.Signature
的用法示例。
在下文中一共展示了Signature.setParameter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createRawSignature
import java.security.Signature; //导入方法依赖的package包/类
public Signature createRawSignature(AlgorithmIdentifier algorithm)
{
Signature sig;
try
{
String algName = getSignatureName(algorithm);
algName = "NONE" + algName.substring(algName.indexOf("WITH"));
sig = helper.createSignature(algName);
// RFC 4056
// When the id-RSASSA-PSS algorithm identifier is used for a signature,
// the AlgorithmIdentifier parameters field MUST contain RSASSA-PSS-params.
if (algorithm.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS))
{
AlgorithmParameters params = helper.createAlgorithmParameters(algName);
params.init(algorithm.getParameters().toASN1Primitive().getEncoded(), "ASN.1");
PSSParameterSpec spec = (PSSParameterSpec)params.getParameterSpec(PSSParameterSpec.class);
sig.setParameter(spec);
}
}
catch (Exception e)
{
return null;
}
return sig;
}
示例2: execute0
import java.security.Signature; //导入方法依赖的package包/类
@Override
protected Object execute0() throws Exception {
KeyStore ks = KeyStore.getInstance("PKCS11", XiSecurityConstants.PROVIDER_NAME_XIPKI);
ks.load(null, null);
if (verbose.booleanValue()) {
println("available aliases:");
Enumeration<?> aliases = ks.aliases();
while (aliases.hasMoreElements()) {
String alias2 = (String) aliases.nextElement();
println(" " + alias2);
}
}
String alias = getAlias();
println("alias: " + alias);
PrivateKey key = (PrivateKey) ks.getKey(alias, null);
if (key == null) {
println("could not find key with alias '" + alias + "'");
return null;
}
Certificate cert = ks.getCertificate(alias);
if (cert == null) {
println("could not find certificate to verify signature");
return null;
}
PublicKey pubKey = cert.getPublicKey();
String sigAlgo = "SM3withSM2";
println("signature algorithm: " + sigAlgo);
Signature sig = Signature.getInstance(sigAlgo, XiSecurityConstants.PROVIDER_NAME_XIPKI);
if (StringUtil.isNotBlank(ida)) {
sig.setParameter(new XiSM2ParameterSpec(ida.getBytes()));
}
sig.initSign(key);
byte[] data = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
sig.update(data);
byte[] signature = sig.sign(); // CHECKSTYLE:SKIP
println("signature created successfully");
Signature ver = Signature.getInstance(sigAlgo, "BC");
if (StringUtil.isNotBlank(ida)) {
ver.setParameter(new SM2ParameterSpec(ida.getBytes()));
}
ver.initVerify(pubKey);
ver.update(data);
boolean valid = ver.verify(signature);
println("signature valid: " + valid);
return null;
}