本文整理汇总了Java中javax.crypto.spec.OAEPParameterSpec.getDigestAlgorithm方法的典型用法代码示例。如果您正苦于以下问题:Java OAEPParameterSpec.getDigestAlgorithm方法的具体用法?Java OAEPParameterSpec.getDigestAlgorithm怎么用?Java OAEPParameterSpec.getDigestAlgorithm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.crypto.spec.OAEPParameterSpec
的用法示例。
在下文中一共展示了OAEPParameterSpec.getDigestAlgorithm方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: engineInit
import javax.crypto.spec.OAEPParameterSpec; //导入方法依赖的package包/类
protected void engineInit(AlgorithmParameterSpec paramSpec)
throws InvalidParameterSpecException {
if (!(paramSpec instanceof OAEPParameterSpec)) {
throw new InvalidParameterSpecException
("Inappropriate parameter specification");
}
OAEPParameterSpec spec = (OAEPParameterSpec) paramSpec;
mdName = spec.getDigestAlgorithm();
String mgfName = spec.getMGFAlgorithm();
if (!mgfName.equalsIgnoreCase("MGF1")) {
throw new InvalidParameterSpecException("Unsupported mgf " +
mgfName + "; MGF1 only");
}
AlgorithmParameterSpec mgfSpec = spec.getMGFParameters();
if (!(mgfSpec instanceof MGF1ParameterSpec)) {
throw new InvalidParameterSpecException("Inappropriate mgf " +
"parameters; non-null MGF1ParameterSpec only");
}
this.mgfSpec = (MGF1ParameterSpec) mgfSpec;
PSource pSrc = spec.getPSource();
if (pSrc.getAlgorithm().equals("PSpecified")) {
p = ((PSource.PSpecified) pSrc).getValue();
} else {
throw new InvalidParameterSpecException("Unsupported pSource " +
pSrc.getAlgorithm() + "; PSpecified only");
}
}
示例2: RSAPadding
import javax.crypto.spec.OAEPParameterSpec; //导入方法依赖的package包/类
private RSAPadding(int type, int paddedSize, SecureRandom random,
OAEPParameterSpec spec) throws InvalidKeyException,
InvalidAlgorithmParameterException {
this.type = type;
this.paddedSize = paddedSize;
this.random = random;
if (paddedSize < 64) {
// sanity check, already verified in RSASignature/RSACipher
throw new InvalidKeyException("Padded size must be at least 64");
}
switch (type) {
case PAD_BLOCKTYPE_1:
case PAD_BLOCKTYPE_2:
maxDataSize = paddedSize - 11;
break;
case PAD_NONE:
maxDataSize = paddedSize;
break;
case PAD_OAEP_MGF1:
String mdName = "SHA-1";
String mgfMdName = "SHA-1";
byte[] digestInput = null;
try {
if (spec != null) {
mdName = spec.getDigestAlgorithm();
String mgfName = spec.getMGFAlgorithm();
if (!mgfName.equalsIgnoreCase("MGF1")) {
throw new InvalidAlgorithmParameterException
("Unsupported MGF algo: " + mgfName);
}
mgfMdName = ((MGF1ParameterSpec)spec.getMGFParameters())
.getDigestAlgorithm();
PSource pSrc = spec.getPSource();
String pSrcAlgo = pSrc.getAlgorithm();
if (!pSrcAlgo.equalsIgnoreCase("PSpecified")) {
throw new InvalidAlgorithmParameterException
("Unsupported pSource algo: " + pSrcAlgo);
}
digestInput = ((PSource.PSpecified) pSrc).getValue();
}
md = MessageDigest.getInstance(mdName);
mgfMd = MessageDigest.getInstance(mgfMdName);
} catch (NoSuchAlgorithmException e) {
throw new InvalidKeyException
("Digest " + mdName + " not available", e);
}
lHash = getInitialHash(md, digestInput);
int digestLen = lHash.length;
maxDataSize = paddedSize - 2 - 2 * digestLen;
if (maxDataSize <= 0) {
throw new InvalidKeyException
("Key is too short for encryption using OAEPPadding" +
" with " + mdName + " and MGF1" + mgfMdName);
}
break;
default:
throw new InvalidKeyException("Invalid padding: " + type);
}
}
示例3: RSAPadding
import javax.crypto.spec.OAEPParameterSpec; //导入方法依赖的package包/类
private RSAPadding(int type, int paddedSize, SecureRandom random,
OAEPParameterSpec spec) throws InvalidKeyException,
InvalidAlgorithmParameterException {
this.type = type;
this.paddedSize = paddedSize;
this.random = random;
if (paddedSize < 64) {
// sanity check, already verified in RSASignature/RSACipher
throw new InvalidKeyException("Padded size must be at least 64");
}
switch (type) {
case PAD_BLOCKTYPE_1:
case PAD_BLOCKTYPE_2:
maxDataSize = paddedSize - 11;
break;
case PAD_NONE:
maxDataSize = paddedSize;
break;
case PAD_OAEP_MGF1:
String mdName = "SHA-1";
String mgfMdName = "SHA-1";
byte[] digestInput = null;
try {
if (spec != null) {
mdName = spec.getDigestAlgorithm();
String mgfName = spec.getMGFAlgorithm();
if (!mgfName.equalsIgnoreCase("MGF1")) {
throw new InvalidAlgorithmParameterException
("Unsupported MGF algo: " + mgfName);
}
mgfMdName = ((MGF1ParameterSpec)spec.getMGFParameters()).getDigestAlgorithm();
PSource pSrc = spec.getPSource();
String pSrcAlgo = pSrc.getAlgorithm();
if (!pSrcAlgo.equalsIgnoreCase("PSpecified")) {
throw new InvalidAlgorithmParameterException
("Unsupported pSource algo: " + pSrcAlgo);
}
digestInput = ((PSource.PSpecified) pSrc).getValue();
}
md = MessageDigest.getInstance(mdName);
mgfMd = MessageDigest.getInstance(mgfMdName);
} catch (NoSuchAlgorithmException e) {
throw new InvalidKeyException
("Digest " + mdName + " not available", e);
}
lHash = getInitialHash(md, digestInput);
int digestLen = lHash.length;
maxDataSize = paddedSize - 2 - 2 * digestLen;
if (maxDataSize <= 0) {
throw new InvalidKeyException
("Key is too short for encryption using OAEPPadding" +
" with " + mdName + " and MGF1" + mgfMdName);
}
break;
default:
throw new InvalidKeyException("Invalid padding: " + type);
}
}