本文整理汇总了Java中javax.crypto.spec.OAEPParameterSpec类的典型用法代码示例。如果您正苦于以下问题:Java OAEPParameterSpec类的具体用法?Java OAEPParameterSpec怎么用?Java OAEPParameterSpec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OAEPParameterSpec类属于javax.crypto.spec包,在下文中一共展示了OAEPParameterSpec类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: engineInit
import javax.crypto.spec.OAEPParameterSpec; //导入依赖的package包/类
protected void engineInit(
int opmode,
Key key,
AlgorithmParameters params,
SecureRandom random)
throws InvalidKeyException, InvalidAlgorithmParameterException
{
AlgorithmParameterSpec paramSpec = null;
if (params != null)
{
try
{
paramSpec = params.getParameterSpec(OAEPParameterSpec.class);
}
catch (InvalidParameterSpecException e)
{
throw new InvalidAlgorithmParameterException("cannot recognise parameters: " + e.toString(), e);
}
}
engineParams = params;
engineInit(opmode, key, paramSpec, random);
}
示例2: engineGetParameters
import javax.crypto.spec.OAEPParameterSpec; //导入依赖的package包/类
protected AlgorithmParameters engineGetParameters() {
if (spec != null && spec instanceof OAEPParameterSpec) {
try {
AlgorithmParameters params =
AlgorithmParameters.getInstance("OAEP",
SunJCE.getInstance());
params.init(spec);
return params;
} catch (NoSuchAlgorithmException nsae) {
// should never happen
throw new RuntimeException("Cannot find OAEP " +
" AlgorithmParameters implementation in SunJCE provider");
} catch (InvalidParameterSpecException ipse) {
// should never happen
throw new RuntimeException("OAEPParameterSpec not supported");
}
} else {
return null;
}
}
示例3: engineInit
import javax.crypto.spec.OAEPParameterSpec; //导入依赖的package包/类
protected void engineInit(int opmode, Key key,
AlgorithmParameters params, SecureRandom random)
throws InvalidKeyException, InvalidAlgorithmParameterException {
if (params == null) {
init(opmode, key, random, null);
} else {
try {
OAEPParameterSpec spec =
params.getParameterSpec(OAEPParameterSpec.class);
init(opmode, key, random, spec);
} catch (InvalidParameterSpecException ipse) {
InvalidAlgorithmParameterException iape =
new InvalidAlgorithmParameterException("Wrong parameter");
iape.initCause(ipse);
throw iape;
}
}
}
示例4: runTest
import javax.crypto.spec.OAEPParameterSpec; //导入依赖的package包/类
private static boolean runTest(String mdName, MGF1ParameterSpec mgfSpec,
byte[] p) throws Exception {
OAEPParameterSpec spec = new OAEPParameterSpec(mdName, "MGF1",
mgfSpec, new PSource.PSpecified(p));
cp = Security.getProvider("SunJCE");
System.out.println("Testing provider " + cp.getName() + "...");
AlgorithmParameters ap = AlgorithmParameters.getInstance("OAEP", cp);
ap.init(spec);
byte[] encoding = ap.getEncoded();
AlgorithmParameters ap2 = AlgorithmParameters.getInstance("OAEP", cp);
ap2.init(encoding);
OAEPParameterSpec spec2 = (OAEPParameterSpec) ap2.getParameterSpec
(OAEPParameterSpec.class);
return compareSpec(spec, spec2);
}
示例5: compareMGF
import javax.crypto.spec.OAEPParameterSpec; //导入依赖的package包/类
private static boolean compareMGF(OAEPParameterSpec s1,
OAEPParameterSpec s2) {
String alg1 = s1.getMGFAlgorithm();
String alg2 = s2.getMGFAlgorithm();
if (alg1.equals(alg2)) {
MGF1ParameterSpec mp1 = (MGF1ParameterSpec)s1.getMGFParameters();
MGF1ParameterSpec mp2 = (MGF1ParameterSpec)s2.getMGFParameters();
alg1 = mp1.getDigestAlgorithm();
alg2 = mp2.getDigestAlgorithm();
if (alg1.equals(alg2)) {
return true;
} else {
System.out.println("MGF's MD algos: " + alg1 + " vs " + alg2);
return false;
}
} else {
System.out.println("MGF algos: " + alg1 + " vs " + alg2);
return false;
}
}
示例6: engineInit
import javax.crypto.spec.OAEPParameterSpec; //导入依赖的package包/类
@Override
protected void engineInit(
int opmode, Key key, AlgorithmParameters params, SecureRandom random)
throws InvalidKeyException, InvalidAlgorithmParameterException {
OAEPParameterSpec spec = null;
if (params != null) {
try {
spec = params.getParameterSpec(OAEPParameterSpec.class);
} catch (InvalidParameterSpecException e) {
throw new InvalidAlgorithmParameterException(
"Only OAEP parameters are supported", e);
}
}
engineInitInternal(opmode, key, spec);
}
示例7: doCryptoInit
import javax.crypto.spec.OAEPParameterSpec; //导入依赖的package包/类
@Override
void doCryptoInit(AlgorithmParameterSpec spec)
throws InvalidAlgorithmParameterException, InvalidKeyException {
pkeyCtx = new NativeRef.EVP_PKEY_CTX(encrypting
? NativeCrypto.EVP_PKEY_encrypt_init(key.getNativeRef())
: NativeCrypto.EVP_PKEY_decrypt_init(key.getNativeRef()));
if (spec instanceof OAEPParameterSpec) {
readOAEPParameters((OAEPParameterSpec) spec);
}
NativeCrypto.EVP_PKEY_CTX_set_rsa_padding(
pkeyCtx.context, NativeConstants.RSA_PKCS1_OAEP_PADDING);
NativeCrypto.EVP_PKEY_CTX_set_rsa_oaep_md(pkeyCtx.context, oaepMd);
NativeCrypto.EVP_PKEY_CTX_set_rsa_mgf1_md(pkeyCtx.context, mgf1Md);
if (label != null && label.length > 0) {
NativeCrypto.EVP_PKEY_CTX_set_rsa_oaep_label(pkeyCtx.context, label);
}
}
示例8: testGetDigestAlgorithm
import javax.crypto.spec.OAEPParameterSpec; //导入依赖的package包/类
/**
* getDigestAlgorithm() method testing.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getDigestAlgorithm",
args = {}
)
public void testGetDigestAlgorithm() {
String mdName = "SHA-1";
String mgfName = "MGF1";
AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
PSource pSrc = PSource.PSpecified.DEFAULT;
OAEPParameterSpec ps = new OAEPParameterSpec(mdName, mgfName,
mgfSpec, pSrc);
assertTrue("The returned value does not equal to the "
+ "value specified in the constructor.",
ps.getDigestAlgorithm().equals(mdName));
}
示例9: testGetMGFAlgorithm
import javax.crypto.spec.OAEPParameterSpec; //导入依赖的package包/类
/**
* getMGFAlgorithm() method testing.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getMGFAlgorithm",
args = {}
)
public void testGetMGFAlgorithm() {
String mdName = "SHA-1";
String mgfName = "MGF1";
AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
PSource pSrc = PSource.PSpecified.DEFAULT;
OAEPParameterSpec ps = new OAEPParameterSpec(mdName, mgfName,
mgfSpec, pSrc);
assertTrue("The returned value does not equal to the "
+ "value specified in the constructor.",
ps.getMGFAlgorithm().equals(mgfName));
}
示例10: testGetMGFParameters
import javax.crypto.spec.OAEPParameterSpec; //导入依赖的package包/类
/**
* getMGFParameters() method testing.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getMGFParameters",
args = {}
)
public void testGetMGFParameters() {
String mdName = "SHA-1";
String mgfName = "MGF1";
AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
PSource pSrc = PSource.PSpecified.DEFAULT;
OAEPParameterSpec ps = new OAEPParameterSpec(mdName, mgfName,
mgfSpec, pSrc);
assertTrue("The returned value does not equal to the "
+ "value specified in the constructor.",
ps.getMGFParameters() == mgfSpec);
}
示例11: testGetPSource
import javax.crypto.spec.OAEPParameterSpec; //导入依赖的package包/类
/**
* getPSource() method testing.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getPSource",
args = {}
)
public void testGetPSource() {
String mdName = "SHA-1";
String mgfName = "MGF1";
AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
PSource pSrc = PSource.PSpecified.DEFAULT;
OAEPParameterSpec ps = new OAEPParameterSpec(mdName, mgfName,
mgfSpec, pSrc);
assertTrue("The returned value does not equal to the "
+ "value specified in the constructor.",
ps.getPSource() == pSrc);
}
示例12: engineInit
import javax.crypto.spec.OAEPParameterSpec; //导入依赖的package包/类
protected void engineInit(int opmode, Key key,
AlgorithmParameters params, SecureRandom random)
throws InvalidKeyException, InvalidAlgorithmParameterException {
if (params == null) {
init(opmode, key, random, null);
} else {
try {
OAEPParameterSpec spec = (OAEPParameterSpec)
params.getParameterSpec(OAEPParameterSpec.class);
init(opmode, key, random, spec);
} catch (InvalidParameterSpecException ipse) {
InvalidAlgorithmParameterException iape =
new InvalidAlgorithmParameterException("Wrong parameter");
iape.initCause(ipse);
throw iape;
}
}
}