本文整理汇总了Java中javax.crypto.spec.PSource类的典型用法代码示例。如果您正苦于以下问题:Java PSource类的具体用法?Java PSource怎么用?Java PSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PSource类属于javax.crypto.spec包,在下文中一共展示了PSource类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: engineGetEncoded
import javax.crypto.spec.PSource; //导入依赖的package包/类
/**
* Return the PKCS#1 ASN.1 structure RSAES-OAEP-params.
*/
protected byte[] engineGetEncoded()
{
AlgorithmIdentifier hashAlgorithm = new AlgorithmIdentifier(
DigestFactory.getOID(currentSpec.getDigestAlgorithm()),
DERNull.INSTANCE);
MGF1ParameterSpec mgfSpec = (MGF1ParameterSpec)currentSpec.getMGFParameters();
AlgorithmIdentifier maskGenAlgorithm = new AlgorithmIdentifier(
PKCSObjectIdentifiers.id_mgf1,
new AlgorithmIdentifier(DigestFactory.getOID(mgfSpec.getDigestAlgorithm()), DERNull.INSTANCE));
PSource.PSpecified pSource = (PSource.PSpecified)currentSpec.getPSource();
AlgorithmIdentifier pSourceAlgorithm = new AlgorithmIdentifier(
PKCSObjectIdentifiers.id_pSpecified, new DEROctetString(pSource.getValue()));
RSAESOAEPparams oaepP = new RSAESOAEPparams(hashAlgorithm, maskGenAlgorithm, pSourceAlgorithm);
try
{
return oaepP.getEncoded(ASN1Encoding.DER);
}
catch (IOException e)
{
throw new RuntimeException("Error encoding OAEPParameters");
}
}
示例2: runTest
import javax.crypto.spec.PSource; //导入依赖的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);
}
示例3: testGetDigestAlgorithm
import javax.crypto.spec.PSource; //导入依赖的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));
}
示例4: testGetMGFAlgorithm
import javax.crypto.spec.PSource; //导入依赖的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));
}
示例5: testGetMGFParameters
import javax.crypto.spec.PSource; //导入依赖的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);
}
示例6: testGetPSource
import javax.crypto.spec.PSource; //导入依赖的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);
}
示例7: testPSpecified
import javax.crypto.spec.PSource; //导入依赖的package包/类
/**
* PSpecified(byte[] p) method testing. Tests that NullPointerException
* is thrown in the case of null p array. Also it checks the value of
* DEFAULT field, and that input p array is copied to protect against
* subsequent modification.
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Nested class.",
clazz = PSource.PSpecified.class,
method = "PSpecified",
args = { byte[].class }
)
public void testPSpecified() {
try {
new PSource.PSpecified(null);
fail("NullPointerException should be thrown in the case of "
+ "null p array.");
} catch (NullPointerException e) {
}
assertEquals("The PSource.PSpecified DEFAULT value should be byte[0]",
0, PSource.PSpecified.DEFAULT.getValue().length);
byte[] p = new byte[] {1, 2, 3, 4, 5};
PSource.PSpecified ps = new PSource.PSpecified(p);
p[0]++;
assertFalse("The change of p specified in the constructor "
+ "should not cause the change of internal array.", p[0] == ps
.getValue()[0]);
}
示例8: testGetAlgorithm
import javax.crypto.spec.PSource; //导入依赖的package包/类
/**
* getAlgorithm() method testing. Tests that returned value is
* equal to the value specified in the constructor.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getAlgorithm",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "PSource",
args = {java.lang.String.class}
)
})
public void testGetAlgorithm() {
String pSrcName = "pSrcName";
PSource ps = new PSource(pSrcName) {};
assertTrue("The returned value is not equal to the value specified "
+ "in constructor", pSrcName.equals(ps.getAlgorithm()));
}
示例9: testPSpecified
import javax.crypto.spec.PSource; //导入依赖的package包/类
/**
* PSpecified(byte[] p) method testing. Tests that NullPointerException
* is thrown in the case of null p array. Also it checks the value of
* DEFAULT field, and that input p array is copied to protect against
* subsequent modification.
*/
public void testPSpecified() {
try {
new PSource.PSpecified(null);
fail("NullPointerException should be thrown in the case of "
+ "null p array.");
} catch (NullPointerException e) {
}
assertEquals("The PSource.PSpecified DEFAULT value should be byte[0]",
0, PSource.PSpecified.DEFAULT.getValue().length);
byte[] p = new byte[] {1, 2, 3, 4, 5};
PSource.PSpecified ps = new PSource.PSpecified(p);
p[0] ++;
assertFalse("The change of p specified in the constructor "
+ "should not cause the change of internal array.",
p[0] == ps.getValue()[0]);
}
示例10: initFromSpec
import javax.crypto.spec.PSource; //导入依赖的package包/类
private void initFromSpec(
OAEPParameterSpec pSpec)
throws NoSuchPaddingException
{
MGF1ParameterSpec mgfParams = (MGF1ParameterSpec)pSpec.getMGFParameters();
Digest digest = DigestFactory.getDigest(mgfParams.getDigestAlgorithm());
if (digest == null)
{
throw new NoSuchPaddingException("no match on OAEP constructor for digest algorithm: "+ mgfParams.getDigestAlgorithm());
}
cipher = new OAEPEncoding(new RSABlindedEngine(), digest, ((PSource.PSpecified)pSpec.getPSource()).getValue());
paramSpec = pSpec;
}
示例11: initFromSpec
import javax.crypto.spec.PSource; //导入依赖的package包/类
private void initFromSpec(
OAEPParameterSpec pSpec)
throws NoSuchPaddingException
{
MGF1ParameterSpec mgfParams = (MGF1ParameterSpec)pSpec.getMGFParameters();
Digest digest = DigestFactory.getDigest(mgfParams.getDigestAlgorithm());
if (digest == null)
{
throw new NoSuchPaddingException("no match on OAEP constructor for digest algorithm: "+ mgfParams.getDigestAlgorithm());
}
cipher = new BufferedAsymmetricBlockCipher(new OAEPEncoding(new ElGamalEngine(), digest, ((PSource.PSpecified)pSpec.getPSource()).getValue()));
paramSpec = pSpec;
}
示例12: engineInit
import javax.crypto.spec.PSource; //导入依赖的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");
}
}
示例13: engineGetParameterSpec
import javax.crypto.spec.PSource; //导入依赖的package包/类
protected <T extends AlgorithmParameterSpec>
T engineGetParameterSpec(Class<T> paramSpec)
throws InvalidParameterSpecException {
if (OAEPParameterSpec.class.isAssignableFrom(paramSpec)) {
return paramSpec.cast(
new OAEPParameterSpec(mdName, "MGF1", mgfSpec,
new PSource.PSpecified(p)));
} else {
throw new InvalidParameterSpecException
("Inappropriate parameter specification");
}
}
示例14: comparePSource
import javax.crypto.spec.PSource; //导入依赖的package包/类
private static boolean comparePSource(OAEPParameterSpec s1,
OAEPParameterSpec s2) {
PSource src1 = s1.getPSource();
PSource src2 = s2.getPSource();
String alg1 = src1.getAlgorithm();
String alg2 = src2.getAlgorithm();
if (alg1.equals(alg2)) {
// assumes they are PSource.PSpecified
return Arrays.equals(((PSource.PSpecified) src1).getValue(),
((PSource.PSpecified) src2).getValue());
} else {
System.out.println("PSource algos: " + alg1 + " vs " + alg2);
return false;
}
}