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


Java PSource.PSpecified方法代码示例

本文整理汇总了Java中javax.crypto.spec.PSource.PSpecified方法的典型用法代码示例。如果您正苦于以下问题:Java PSource.PSpecified方法的具体用法?Java PSource.PSpecified怎么用?Java PSource.PSpecified使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.crypto.spec.PSource的用法示例。


在下文中一共展示了PSource.PSpecified方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例4: 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

示例5: readOAEPParameters

import javax.crypto.spec.PSource; //导入方法依赖的package包/类
private void readOAEPParameters(OAEPParameterSpec spec)
        throws InvalidAlgorithmParameterException {
    String mgfAlgUpper = spec.getMGFAlgorithm().toUpperCase(Locale.US);
    AlgorithmParameterSpec mgfSpec = spec.getMGFParameters();
    if ((!EvpMdRef.MGF1_ALGORITHM_NAME.equals(mgfAlgUpper)
                && !EvpMdRef.MGF1_OID.equals(mgfAlgUpper))
            || !(mgfSpec instanceof MGF1ParameterSpec)) {
        throw new InvalidAlgorithmParameterException(
                "Only MGF1 supported as mask generation function");
    }

    MGF1ParameterSpec mgf1spec = (MGF1ParameterSpec) mgfSpec;
    String oaepAlgUpper = spec.getDigestAlgorithm().toUpperCase(Locale.US);
    try {
        oaepMd = EvpMdRef.getEVP_MDByJcaDigestAlgorithmStandardName(oaepAlgUpper);
        oaepMdSizeBytes =
                EvpMdRef.getDigestSizeBytesByJcaDigestAlgorithmStandardName(oaepAlgUpper);
        mgf1Md = EvpMdRef.getEVP_MDByJcaDigestAlgorithmStandardName(
                mgf1spec.getDigestAlgorithm());
    } catch (NoSuchAlgorithmException e) {
        throw new InvalidAlgorithmParameterException(e);
    }

    PSource pSource = spec.getPSource();
    if (!"PSpecified".equals(pSource.getAlgorithm())
            || !(pSource instanceof PSource.PSpecified)) {
        throw new InvalidAlgorithmParameterException(
                "Only PSpecified accepted for PSource");
    }
    label = ((PSource.PSpecified) pSource).getValue();
}
 
开发者ID:google,项目名称:conscrypt,代码行数:32,代码来源:OpenSSLCipherRSA.java

示例6: testGetValue

import javax.crypto.spec.PSource; //导入方法依赖的package包/类
/**
 * getValue() method testing. Tests that returned array is equal to the
 * array specified in the constructor. Checks that modification
 * of returned array does not affect the internal array.
 */
@TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "",
        clazz = PSource.PSpecified.class,
        method = "PSpecified",
        args = {byte[].class}
    ),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "",
        clazz = PSource.PSpecified.class,
        method = "getValue",
        args = {}
    )
})
public void testGetValue() {
    byte[] p = new byte[] {1, 2, 3, 4, 5};

    PSource.PSpecified ps = new PSource.PSpecified(p);
    byte[] result = ps.getValue();
    if (!Arrays.equals(p, result)) {
        fail("The returned array does not equal to the specified "
                + "in the constructor.");
    }
    result[0]++;
    assertFalse("The change of returned by getValue() array "
            + "should not cause the change of internal array.",
            result[0] == ps.getValue()[0]);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:36,代码来源:PSourceTest.java

示例7: engineGetParameterSpec

import javax.crypto.spec.PSource; //导入方法依赖的package包/类
protected AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec)
    throws InvalidParameterSpecException {
    if (OAEPParameterSpec.class.isAssignableFrom(paramSpec)) {
        return new OAEPParameterSpec(mdName, "MGF1", mgfSpec,
            new PSource.PSpecified(p));
    } else {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:11,代码来源:OAEPParameters.java

示例8: testGetValue

import javax.crypto.spec.PSource; //导入方法依赖的package包/类
/**
 * getValue() method testing. Tests that returned array is equal to the
 * array specified in the constructor. Checks that modification
 * of returned array does not affect the internal array.
 */
public void testGetValue() {
    byte[] p = new byte[] {1, 2, 3, 4, 5};

    PSource.PSpecified ps = new PSource.PSpecified(p);
    byte[] result = ps.getValue();
    if (! Arrays.equals(p, result)) {
        fail("The returned array does not equal to the specified "
                + "in the constructor.");
    }
    result[0] ++;
    assertFalse("The change of returned by getValue() array "
                + "should not cause the change of internal array.",
                result[0] == ps.getValue()[0]);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:20,代码来源:PSourceTest.java

示例9: engineInit

import javax.crypto.spec.PSource; //导入方法依赖的package包/类
@Override
protected void engineInit(byte[] bytes) throws IOException {
    long readRef = 0;
    long seqRef = 0;
    try {
        readRef = NativeCrypto.asn1_read_init(bytes);
        seqRef = NativeCrypto.asn1_read_sequence(readRef);
        String hash = "SHA-1";
        String mgfHash = "SHA-1";
        PSource.PSpecified pSpecified = PSource.PSpecified.DEFAULT;
        if (NativeCrypto.asn1_read_next_tag_is(seqRef, 0)) {
            long hashRef = 0;
            try {
                hashRef = NativeCrypto.asn1_read_tagged(seqRef);
                hash = getHashName(hashRef);
            } finally {
                NativeCrypto.asn1_read_free(hashRef);
            }
        }
        if (NativeCrypto.asn1_read_next_tag_is(seqRef, 1)) {
            long mgfRef = 0;
            long mgfSeqRef = 0;
            try {
                mgfRef = NativeCrypto.asn1_read_tagged(seqRef);
                mgfSeqRef = NativeCrypto.asn1_read_sequence(mgfRef);
                String mgfOid = NativeCrypto.asn1_read_oid(mgfSeqRef);
                if (!mgfOid.equals(MGF1_OID)) {
                    throw new IOException("Error reading ASN.1 encoding");
                }
                mgfHash = getHashName(mgfSeqRef);
                if (!NativeCrypto.asn1_read_is_empty(mgfSeqRef)) {
                    throw new IOException("Error reading ASN.1 encoding");
                }
            } finally {
                NativeCrypto.asn1_read_free(mgfSeqRef);
                NativeCrypto.asn1_read_free(mgfRef);
            }
        }
        if (NativeCrypto.asn1_read_next_tag_is(seqRef, 2)) {
            long pSourceRef = 0;
            long pSourceSeqRef = 0;
            try {
                pSourceRef = NativeCrypto.asn1_read_tagged(seqRef);
                pSourceSeqRef = NativeCrypto.asn1_read_sequence(pSourceRef);
                String pSourceOid = NativeCrypto.asn1_read_oid(pSourceSeqRef);
                if (!pSourceOid.equals(PSPECIFIED_OID)) {
                    throw new IOException("Error reading ASN.1 encoding");
                }
                pSpecified = new PSource.PSpecified(
                        NativeCrypto.asn1_read_octetstring(pSourceSeqRef));
                if (!NativeCrypto.asn1_read_is_empty(pSourceSeqRef)) {
                    throw new IOException("Error reading ASN.1 encoding");
                }
            } finally {
                NativeCrypto.asn1_read_free(pSourceSeqRef);
                NativeCrypto.asn1_read_free(pSourceRef);
            }
        }

        if (!NativeCrypto.asn1_read_is_empty(seqRef)
                || !NativeCrypto.asn1_read_is_empty(readRef)) {
            throw new IOException("Error reading ASN.1 encoding");
        }
        this.spec = new OAEPParameterSpec(hash, "MGF1", new MGF1ParameterSpec(mgfHash),
                pSpecified);
    } finally {
        NativeCrypto.asn1_read_free(seqRef);
        NativeCrypto.asn1_read_free(readRef);
    }
}
 
开发者ID:google,项目名称:conscrypt,代码行数:71,代码来源:OAEPParameters.java

示例10: doTestKeyTransOAEPDefaultNamed

import javax.crypto.spec.PSource; //导入方法依赖的package包/类
private void doTestKeyTransOAEPDefaultNamed(String digest, String mgfDigest)
    throws Exception
{
    byte[]          data     = "WallaWallaWashington".getBytes();

    CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();
    JcaAlgorithmParametersConverter  paramsConverter = new JcaAlgorithmParametersConverter();

    OAEPParameterSpec oaepSpec = new OAEPParameterSpec(digest, "MGF1", new MGF1ParameterSpec(mgfDigest), new PSource.PSpecified(new byte[]{1, 2, 3, 4, 5}));
    AlgorithmIdentifier oaepAlgId = paramsConverter.getAlgorithmIdentifier(PKCSObjectIdentifiers.id_RSAES_OAEP, oaepSpec);

    edGen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCert, oaepAlgId).setProvider(BC));
    edGen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(ASN1OctetString.getInstance(ASN1OctetString.getInstance(_reciCert.getExtensionValue(Extension.subjectKeyIdentifier.getId())).getOctets()).getOctets(), oaepAlgId, _reciCert.getPublicKey()).setProvider(BC));

    CMSEnvelopedData ed = edGen.generate(
                            new CMSProcessableByteArray(data),
                            new JceCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC).setProvider(BC).build());

    RecipientInformationStore  recipients = ed.getRecipientInfos();


    assertEquals(ed.getEncryptionAlgOID(), CMSEnvelopedDataGenerator.DES_EDE3_CBC);

    Collection  c = recipients.getRecipients();

    assertEquals(2, c.size());

    Iterator    it = c.iterator();

    while (it.hasNext())
    {
        RecipientInformation   recipient = (RecipientInformation)it.next();

        assertEquals(PKCSObjectIdentifiers.id_RSAES_OAEP, recipient.getKeyEncryptionAlgorithm().getAlgorithm());

        byte[] recData = recipient.getContent(new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC));

        assertEquals(true, Arrays.equals(data, recData));
    }

    RecipientId id = new JceKeyTransRecipientId(_reciCert);

    Collection collection = recipients.getRecipients(id);
    if (collection.size() != 2)
    {
        fail("recipients not matched using general recipient ID.");
    }
    assertTrue(collection.iterator().next() instanceof RecipientInformation);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:50,代码来源:NewEnvelopedDataTest.java


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