本文整理汇总了Java中java.security.spec.PSSParameterSpec.getSaltLength方法的典型用法代码示例。如果您正苦于以下问题:Java PSSParameterSpec.getSaltLength方法的具体用法?Java PSSParameterSpec.getSaltLength怎么用?Java PSSParameterSpec.getSaltLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.spec.PSSParameterSpec
的用法示例。
在下文中一共展示了PSSParameterSpec.getSaltLength方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: engineGetEncoded
import java.security.spec.PSSParameterSpec; //导入方法依赖的package包/类
/**
* Return the PKCS#1 ASN.1 structure RSASSA-PSS-params.
*/
protected byte[] engineGetEncoded()
throws IOException
{
PSSParameterSpec pssSpec = currentSpec;
AlgorithmIdentifier hashAlgorithm = new AlgorithmIdentifier(
DigestFactory.getOID(pssSpec.getDigestAlgorithm()),
DERNull.INSTANCE);
MGF1ParameterSpec mgfSpec = (MGF1ParameterSpec)pssSpec.getMGFParameters();
AlgorithmIdentifier maskGenAlgorithm = new AlgorithmIdentifier(
PKCSObjectIdentifiers.id_mgf1,
new AlgorithmIdentifier(DigestFactory.getOID(mgfSpec.getDigestAlgorithm()), DERNull.INSTANCE));
RSASSAPSSparams pssP = new RSASSAPSSparams(hashAlgorithm, maskGenAlgorithm, new ASN1Integer(pssSpec.getSaltLength()), new ASN1Integer(pssSpec.getTrailerField()));
return pssP.getEncoded("DER");
}
示例2: engineGetEncoded
import java.security.spec.PSSParameterSpec; //导入方法依赖的package包/类
/**
* Return the PKCS#1 ASN.1 structure RSASSA-PSS-params.
*/
protected byte[] engineGetEncoded()
{
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
DEROutputStream dOut = new DEROutputStream(bOut);
PSSParameterSpec pssSpec = (PSSParameterSpec)currentSpec;
RSASSAPSSparams pssP = new RSASSAPSSparams(RSASSAPSSparams.DEFAULT_HASH_ALGORITHM, RSASSAPSSparams.DEFAULT_MASK_GEN_FUNCTION, new DERInteger(pssSpec.getSaltLength()), RSASSAPSSparams.DEFAULT_TRAILER_FIELD);
try
{
dOut.writeObject(pssP);
dOut.close();
}
catch (IOException e)
{
throw new RuntimeException("Error encoding PSSParameters");
}
return bOut.toByteArray();
}
示例3: engineGetEncoded
import java.security.spec.PSSParameterSpec; //导入方法依赖的package包/类
/**
* Return the PKCS#1 ASN.1 structure RSASSA-PSS-params.
*/
protected byte[] engineGetEncoded()
throws IOException
{
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
DEROutputStream dOut = new DEROutputStream(bOut);
PSSParameterSpec pssSpec = (PSSParameterSpec)currentSpec;
RSASSAPSSparams pssP = new RSASSAPSSparams(RSASSAPSSparams.DEFAULT_HASH_ALGORITHM, RSASSAPSSparams.DEFAULT_MASK_GEN_FUNCTION, new ASN1Integer(pssSpec.getSaltLength()), RSASSAPSSparams.DEFAULT_TRAILER_FIELD);
dOut.writeObject(pssP);
dOut.close();
return bOut.toByteArray();
}
示例4: engineSetParameter
import java.security.spec.PSSParameterSpec; //导入方法依赖的package包/类
@Override
protected final void engineSetParameter(AlgorithmParameterSpec params)
throws InvalidAlgorithmParameterException {
if (!(params instanceof PSSParameterSpec)) {
throw new InvalidAlgorithmParameterException(
"Unsupported parameter: " + params + ". Only "
+ PSSParameterSpec.class.getName() + " supported");
}
PSSParameterSpec spec = (PSSParameterSpec) params;
String specContentDigest = EvpMdRef
.getJcaDigestAlgorithmStandardName(spec.getDigestAlgorithm());
if (specContentDigest == null) {
throw new InvalidAlgorithmParameterException(
"Unsupported content digest algorithm: " + spec.getDigestAlgorithm());
} else if (!contentDigestAlgorithm.equalsIgnoreCase(specContentDigest)) {
throw new InvalidAlgorithmParameterException(
"Changing content digest algorithm not supported");
}
String specMgfAlgorithm = spec.getMGFAlgorithm();
if ((!EvpMdRef.MGF1_ALGORITHM_NAME.equalsIgnoreCase(specMgfAlgorithm))
&& (!EvpMdRef.MGF1_OID.equals(specMgfAlgorithm))) {
throw new InvalidAlgorithmParameterException(
"Unsupported MGF algorithm: " + specMgfAlgorithm + ". Only "
+ EvpMdRef.MGF1_ALGORITHM_NAME + " supported");
}
AlgorithmParameterSpec mgfSpec = spec.getMGFParameters();
if (!(mgfSpec instanceof MGF1ParameterSpec)) {
throw new InvalidAlgorithmParameterException(
"Unsupported MGF parameters: " + mgfSpec + ". Only "
+ MGF1ParameterSpec.class.getName() + " supported");
}
MGF1ParameterSpec specMgf1Spec = (MGF1ParameterSpec) spec.getMGFParameters();
String specMgf1Digest = EvpMdRef
.getJcaDigestAlgorithmStandardName(specMgf1Spec.getDigestAlgorithm());
if (specMgf1Digest == null) {
throw new InvalidAlgorithmParameterException(
"Unsupported MGF1 digest algorithm: " + specMgf1Spec.getDigestAlgorithm());
}
long specMgf1EvpMdRef;
try {
specMgf1EvpMdRef = EvpMdRef
.getEVP_MDByJcaDigestAlgorithmStandardName(specMgf1Digest);
} catch (NoSuchAlgorithmException e) {
throw new ProviderException("Failed to obtain EVP_MD for " + specMgf1Digest, e);
}
int specSaltSizeBytes = spec.getSaltLength();
if (specSaltSizeBytes < 0) {
throw new InvalidAlgorithmParameterException(
"Salt length must be non-negative: " + specSaltSizeBytes);
}
int specTrailer = spec.getTrailerField();
if (specTrailer != TRAILER_FIELD_BC_ID) {
throw new InvalidAlgorithmParameterException(
"Unsupported trailer field: " + specTrailer + ". Only "
+ TRAILER_FIELD_BC_ID + " supported");
}
this.mgf1DigestAlgorithm = specMgf1Digest;
this.mgf1EvpMdRef = specMgf1EvpMdRef;
this.saltSizeBytes = specSaltSizeBytes;
long ctx = getEVP_PKEY_CTX();
if (ctx != 0) {
configureEVP_PKEY_CTX(ctx);
}
}
示例5: rawModeTest
import java.security.spec.PSSParameterSpec; //导入方法依赖的package包/类
private void rawModeTest(String sigName, DERObjectIdentifier digestOID,
PrivateKey privKey, PublicKey pubKey, SecureRandom random) throws Exception
{
byte[] sampleMessage = new byte[1000 + random.nextInt(100)];
random.nextBytes(sampleMessage);
Signature normalSig = Signature.getInstance(sigName, "BC");
PSSParameterSpec spec = (PSSParameterSpec)normalSig.getParameters().getParameterSpec(PSSParameterSpec.class);
// Make sure we generate the same 'random' salt for both normal and raw signers
int saltLen = spec.getSaltLength();
byte[] fixedRandomBytes = new byte[saltLen];
random.nextBytes(fixedRandomBytes);
normalSig.initSign(privKey, new FixedSecureRandom(fixedRandomBytes));
normalSig.update(sampleMessage);
byte[] normalResult = normalSig.sign();
MessageDigest digest = MessageDigest.getInstance(digestOID.getId(), "BC");
byte[] hash = digest.digest(sampleMessage);
Signature rawSig = Signature.getInstance("RAWRSASSA-PSS", "BC");
// Need to init the params explicitly to avoid having a 'raw' variety of every PSS algorithm
rawSig.setParameter(spec);
rawSig.initSign(privKey, new FixedSecureRandom(fixedRandomBytes));
rawSig.update(hash);
byte[] rawResult = rawSig.sign();
if (!Arrays.areEqual(normalResult, rawResult))
{
fail("raw mode signature differs from normal one");
}
rawSig.initVerify(pubKey);
rawSig.update(hash);
if (!rawSig.verify(rawResult))
{
fail("raw mode signature verification failed");
}
}