当前位置: 首页>>代码示例>>Java>>正文


Java PSource类代码示例

本文整理汇总了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");
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:27,代码来源:AlgorithmParametersSpi.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:TestOAEPParameterSpec.java

示例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));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:22,代码来源:OAEPParameterSpecTest.java

示例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));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:22,代码来源:OAEPParameterSpecTest.java

示例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);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:22,代码来源:OAEPParameterSpecTest.java

示例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);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:22,代码来源:OAEPParameterSpecTest.java

示例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]);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:32,代码来源:PSourceTest.java

示例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()));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:25,代码来源:PSourceTest.java

示例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]);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:25,代码来源:PSourceTest.java

示例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;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:16,代码来源:CipherSpi.java

示例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;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:16,代码来源:CipherSpi.java

示例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");
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:OAEPParameters.java

示例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");
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:OAEPParameters.java

示例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;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:TestOAEPParameterSpec.java


注:本文中的javax.crypto.spec.PSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。