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


Java PGPLiteralData.getInputStream方法代码示例

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


在下文中一共展示了PGPLiteralData.getInputStream方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: bufferTest

import org.bouncycastle.openpgp.PGPLiteralData; //导入方法依赖的package包/类
private void bufferTest(
    PGPLiteralDataGenerator generator, 
    byte[] buf, 
    int i)
    throws IOException
{
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    OutputStream out = generator.open(
        new UncloseableOutputStream(bOut),
        PGPLiteralData.BINARY,
        PGPLiteralData.CONSOLE,
        i,
        new Date());

    out.write(buf, 0, i);
    
    generator.close();
    
    PGPObjectFactory        fact = new PGPObjectFactory(bOut.toByteArray());
    PGPLiteralData          data = (PGPLiteralData)fact.nextObject();
    InputStream             in = data.getInputStream();

    for (int count = 0; count != i; count++)
    {
        if (in.read() != (buf[count] & 0xff))
        {
            fail("failed readback test - length = " + i);
        }
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:31,代码来源:PGPPacketTest.java

示例2: decryptMessage

import org.bouncycastle.openpgp.PGPLiteralData; //导入方法依赖的package包/类
/**
 * decrypt the passed in message stream
 */
private byte[] decryptMessage(
    byte[]    message,
    Date      date)
    throws Exception
{
    PGPObjectFactory         pgpF = new BcPGPObjectFactory(message);
    PGPEncryptedDataList     enc = (PGPEncryptedDataList)pgpF.nextObject();
    PGPPBEEncryptedData      pbe = (PGPPBEEncryptedData)enc.get(0);

    InputStream clear = pbe.getDataStream(new BcPBEDataDecryptorFactory(pass, new BcPGPDigestCalculatorProvider()));
    
    PGPObjectFactory         pgpFact = new BcPGPObjectFactory(clear);
    
    PGPLiteralData           ld = (PGPLiteralData)pgpFact.nextObject();
    
    ByteArrayOutputStream    bOut = new ByteArrayOutputStream();
    if (!ld.getFileName().equals("test.txt")
        && !ld.getFileName().equals("_CONSOLE"))
    {
        fail("wrong filename in packet");
    }
    if (!ld.getModificationTime().equals(date))
    {
        fail("wrong modification time in packet: " + ld.getModificationTime().getTime() + " " + date.getTime());
    }

    InputStream              unc = ld.getInputStream();
    int                      ch;
    
    while ((ch = unc.read()) >= 0)
    {
        bOut.write(ch);
    }

    if (pbe.isIntegrityProtected() && !pbe.verify())
    {
        fail("integrity check failed");
    }

    return bOut.toByteArray();
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:45,代码来源:BcPGPPBETest.java

示例3: decryptMessageBuffered

import org.bouncycastle.openpgp.PGPLiteralData; //导入方法依赖的package包/类
private byte[] decryptMessageBuffered(
    byte[]    message,
    Date      date)
    throws Exception
{
    PGPObjectFactory         pgpF = new PGPObjectFactory(message, new BcKeyFingerprintCalculator());
    PGPEncryptedDataList     enc = (PGPEncryptedDataList)pgpF.nextObject();
    PGPPBEEncryptedData      pbe = (PGPPBEEncryptedData)enc.get(0);

    InputStream clear = pbe.getDataStream(new BcPBEDataDecryptorFactory(pass, new BcPGPDigestCalculatorProvider()));

    PGPObjectFactory         pgpFact = new PGPObjectFactory(clear, new BcKeyFingerprintCalculator());

    PGPLiteralData           ld = (PGPLiteralData)pgpFact.nextObject();

    ByteArrayOutputStream    bOut = new ByteArrayOutputStream();
    if (!ld.getFileName().equals("test.txt")
        && !ld.getFileName().equals("_CONSOLE"))
    {
        fail("wrong filename in packet");
    }
    if (!ld.getModificationTime().equals(date))
    {
        fail("wrong modification time in packet: " + ld.getModificationTime().getTime() + " " + date.getTime());
    }

    InputStream              unc = ld.getInputStream();
    byte[]                   buf = new byte[1024];
    int                      len;

    while ((len = unc.read(buf)) >= 0)
    {
        bOut.write(buf, 0, len);
    }

    if (pbe.isIntegrityProtected() && !pbe.verify())
    {
        fail("integrity check failed");
    }

    return bOut.toByteArray();
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:43,代码来源:BcPGPPBETest.java

示例4: generateTest

import org.bouncycastle.openpgp.PGPLiteralData; //导入方法依赖的package包/类
/**
 * Generated signature test
 * 
 * @param sKey
 * @param pgpPrivKey
 */
public void generateTest(
    PGPSecretKeyRing sKey,
    PGPPublicKey     pgpPubKey,
    PGPPrivateKey    pgpPrivKey)
    throws Exception
{
    String                  data = "hello world!";
    ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
    ByteArrayInputStream    testIn = new ByteArrayInputStream(data.getBytes());
    PGPSignatureGenerator   sGen = new PGPSignatureGenerator(new BcPGPContentSignerBuilder(PublicKeyAlgorithmTags.DSA, HashAlgorithmTags.SHA1));

    sGen.init(PGPSignature.BINARY_DOCUMENT, pgpPrivKey);

    PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
    
    Iterator        it = sKey.getSecretKey().getPublicKey().getUserIDs();
    String          primaryUserID = (String)it.next();
    
    spGen.setSignerUserID(true, primaryUserID);
    
    sGen.setHashedSubpackets(spGen.generate());

    sGen.generateOnePassVersion(false).encode(bOut);

    PGPLiteralDataGenerator lGen = new PGPLiteralDataGenerator();
    
    Date testDate = new Date((System.currentTimeMillis() / 1000) * 1000);
    OutputStream lOut = lGen.open(
        new UncloseableOutputStream(bOut),
        PGPLiteralData.BINARY,
        "_CONSOLE",
        data.getBytes().length,
        testDate);

    int ch;
    while ((ch = testIn.read()) >= 0)
    {
        lOut.write(ch);
        sGen.update((byte)ch);
    }

    lGen.close();

    sGen.generate().encode(bOut);

    PGPObjectFactory        pgpFact = new BcPGPObjectFactory(bOut.toByteArray());

    PGPOnePassSignatureList p1 = (PGPOnePassSignatureList)pgpFact.nextObject();
    PGPOnePassSignature     ops = p1.get(0);
    
    PGPLiteralData          p2 = (PGPLiteralData)pgpFact.nextObject();
    if (!p2.getModificationTime().equals(testDate))
    {
        fail("Modification time not preserved");
    }

    InputStream             dIn = p2.getInputStream();

    ops.init(new BcPGPContentVerifierBuilderProvider(), pgpPubKey);
    
    while ((ch = dIn.read()) >= 0)
    {
        ops.update((byte)ch);
    }

    PGPSignatureList p3 = (PGPSignatureList)pgpFact.nextObject();

    if (!ops.verify(p3.get(0)))
    {
        fail("Failed generated signature check");
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:79,代码来源:BcPGPDSATest.java

示例5: getInputStream

import org.bouncycastle.openpgp.PGPLiteralData; //导入方法依赖的package包/类
private static InputStream getInputStream( JcaPGPObjectFactory objectFactory ) throws IOException
{
    PGPLiteralData literalData = ( PGPLiteralData ) objectFactory.nextObject();

    return literalData.getInputStream();
}
 
开发者ID:subutai-io,项目名称:base,代码行数:7,代码来源:PGPVerify.java

示例6: getInputStream

import org.bouncycastle.openpgp.PGPLiteralData; //导入方法依赖的package包/类
private static InputStream getInputStream( PGPPrivateKey privateKey, PGPPublicKeyEncryptedData pgpEncData )
        throws PGPException, IOException
{
    InputStream is = pgpEncData
            .getDataStream( new JcePublicKeyDataDecryptorFactoryBuilder().setProvider( "BC" ).build( privateKey ) );

    JcaPGPObjectFactory objectFactory = new JcaPGPObjectFactory( is );

    Object message = objectFactory.nextObject();

    PGPCompressedData compressedData = ( PGPCompressedData ) message;

    JcaPGPObjectFactory pgpObjectFactory = new JcaPGPObjectFactory( compressedData.getDataStream() );

    PGPLiteralData literalData = ( PGPLiteralData ) pgpObjectFactory.nextObject();

    return literalData.getInputStream();
}
 
开发者ID:subutai-io,项目名称:base,代码行数:19,代码来源:PGPDecrypt.java

示例7: verifySignature

import org.bouncycastle.openpgp.PGPLiteralData; //导入方法依赖的package包/类
private void verifySignature(
    byte[] encodedSig, 
    int hashAlgorithm, 
    PGPPublicKey pubKey,  
    byte[] original) 
    throws IOException, PGPException, NoSuchProviderException, SignatureException
{
    PGPObjectFactory        pgpFact = new PGPObjectFactory(encodedSig);
    PGPOnePassSignatureList p1 = (PGPOnePassSignatureList)pgpFact.nextObject();
    PGPOnePassSignature     ops = p1.get(0);
    PGPLiteralData          p2 = (PGPLiteralData)pgpFact.nextObject();
    InputStream             dIn = p2.getInputStream();

    ops.init(new JcaPGPContentVerifierBuilderProvider().setProvider("BC"), pubKey);
    
    int ch;

    while ((ch = dIn.read()) >= 0)
    {
        ops.update((byte)ch);
    }

    PGPSignatureList p3 = (PGPSignatureList)pgpFact.nextObject();
    PGPSignature sig = p3.get(0);

    Date creationTime = sig.getCreationTime();
    Date now = new Date();

    // Check creationTime is recent
    if (creationTime.after(now)
        || creationTime.before(new Date(now.getTime() - 10 * 60 * 1000)))
    {
        fail("bad creation time in signature: " + creationTime);
    }

    if (sig.getKeyID() != pubKey.getKeyID())
    {
        fail("key id mismatch in signature");
    }
    
    if (!ops.verify(sig))
    {
        fail("Failed generated signature check - " + hashAlgorithm);
    }
    
    sig.init(new JcaPGPContentVerifierBuilderProvider().setProvider("BC"), pubKey);
    
    for (int i = 0; i != original.length; i++)
    {
        sig.update(original[i]);
    }
    
    sig.update(original);
    
    if (!sig.verify())
    {
        fail("Failed generated signature check against original data");
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:60,代码来源:PGPSignatureTest.java

示例8: doSigGenerateTest

import org.bouncycastle.openpgp.PGPLiteralData; //导入方法依赖的package包/类
private void doSigGenerateTest(String privateKeyFile, String publicKeyFile, int digest)
    throws Exception
{
    PGPSecretKeyRing      secRing = loadSecretKey(privateKeyFile);
    PGPPublicKeyRing      pubRing = loadPublicKey(publicKeyFile);
    String                data = "hello world!";
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    ByteArrayInputStream  testIn = new ByteArrayInputStream(data.getBytes());
    PGPSignatureGenerator sGen = new PGPSignatureGenerator(PublicKeyAlgorithmTags.DSA, digest, "BC");

    sGen.initSign(PGPSignature.BINARY_DOCUMENT, secRing.getSecretKey().extractPrivateKey("test".toCharArray(), "BC"));

    BCPGOutputStream bcOut = new BCPGOutputStream(bOut);

    sGen.generateOnePassVersion(false).encode(bcOut);

    PGPLiteralDataGenerator lGen = new PGPLiteralDataGenerator();

    Date testDate = new Date((System.currentTimeMillis() / 1000) * 1000);
    OutputStream lOut = lGen.open(
        new UncloseableOutputStream(bcOut),
        PGPLiteralData.BINARY,
        "_CONSOLE",
        data.getBytes().length,
        testDate);

    int ch;
    while ((ch = testIn.read()) >= 0)
    {
        lOut.write(ch);
        sGen.update((byte)ch);
    }

    lGen.close();

    sGen.generate().encode(bcOut);

    PGPObjectFactory        pgpFact = new PGPObjectFactory(bOut.toByteArray());
    PGPOnePassSignatureList p1 = (PGPOnePassSignatureList)pgpFact.nextObject();
    PGPOnePassSignature     ops = p1.get(0);

    assertEquals(digest, ops.getHashAlgorithm());
    assertEquals(PublicKeyAlgorithmTags.DSA, ops.getKeyAlgorithm());

    PGPLiteralData          p2 = (PGPLiteralData)pgpFact.nextObject();
    if (!p2.getModificationTime().equals(testDate))
    {
        fail("Modification time not preserved");
    }

    InputStream             dIn = p2.getInputStream();

    ops.initVerify(pubRing.getPublicKey(), "BC");

    while ((ch = dIn.read()) >= 0)
    {
        ops.update((byte)ch);
    }

    PGPSignatureList p3 = (PGPSignatureList)pgpFact.nextObject();
    PGPSignature sig = p3.get(0);

    assertEquals(digest, sig.getHashAlgorithm());
    assertEquals(PublicKeyAlgorithmTags.DSA, sig.getKeyAlgorithm());

    assertTrue(ops.verify(sig));
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:68,代码来源:DSA2Test.java

示例9: decryptMessage

import org.bouncycastle.openpgp.PGPLiteralData; //导入方法依赖的package包/类
/**
 * decrypt the passed in message stream
 */
private byte[] decryptMessage(
    byte[]    message,
    Date      date)
    throws Exception
{
    PGPObjectFactory         pgpF = new PGPObjectFactory(message);
    PGPEncryptedDataList     enc = (PGPEncryptedDataList)pgpF.nextObject();
    PGPPBEEncryptedData      pbe = (PGPPBEEncryptedData)enc.get(0);

    InputStream clear = pbe.getDataStream(new BcPBEDataDecryptorFactory(pass, new BcPGPDigestCalculatorProvider()));
    
    PGPObjectFactory         pgpFact = new PGPObjectFactory(clear);
    
    PGPLiteralData           ld = (PGPLiteralData)pgpFact.nextObject();
    
    ByteArrayOutputStream    bOut = new ByteArrayOutputStream();
    if (!ld.getFileName().equals("test.txt")
        && !ld.getFileName().equals("_CONSOLE"))
    {
        fail("wrong filename in packet");
    }
    if (!ld.getModificationTime().equals(date))
    {
        fail("wrong modification time in packet: " + ld.getModificationTime().getTime() + " " + date.getTime());
    }

    InputStream              unc = ld.getInputStream();
    int                      ch;
    
    while ((ch = unc.read()) >= 0)
    {
        bOut.write(ch);
    }

    if (pbe.isIntegrityProtected() && !pbe.verify())
    {
        fail("integrity check failed");
    }

    return bOut.toByteArray();
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:45,代码来源:BcPGPPBETest.java

示例10: decryptMessageBuffered

import org.bouncycastle.openpgp.PGPLiteralData; //导入方法依赖的package包/类
private byte[] decryptMessageBuffered(
    byte[]    message,
    Date      date)
    throws Exception
{
    PGPObjectFactory         pgpF = new PGPObjectFactory(message);
    PGPEncryptedDataList     enc = (PGPEncryptedDataList)pgpF.nextObject();
    PGPPBEEncryptedData      pbe = (PGPPBEEncryptedData)enc.get(0);

    InputStream clear = pbe.getDataStream(new BcPBEDataDecryptorFactory(pass, new BcPGPDigestCalculatorProvider()));

    PGPObjectFactory         pgpFact = new PGPObjectFactory(clear);;

    PGPLiteralData           ld = (PGPLiteralData)pgpFact.nextObject();

    ByteArrayOutputStream    bOut = new ByteArrayOutputStream();
    if (!ld.getFileName().equals("test.txt")
        && !ld.getFileName().equals("_CONSOLE"))
    {
        fail("wrong filename in packet");
    }
    if (!ld.getModificationTime().equals(date))
    {
        fail("wrong modification time in packet: " + ld.getModificationTime().getTime() + " " + date.getTime());
    }

    InputStream              unc = ld.getInputStream();
    byte[]                   buf = new byte[1024];
    int                      len;

    while ((len = unc.read(buf)) >= 0)
    {
        bOut.write(buf, 0, len);
    }

    if (pbe.isIntegrityProtected() && !pbe.verify())
    {
        fail("integrity check failed");
    }

    return bOut.toByteArray();
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:43,代码来源:BcPGPPBETest.java

示例11: generateTest

import org.bouncycastle.openpgp.PGPLiteralData; //导入方法依赖的package包/类
/**
 * Generated signature test
 * 
 * @param sKey
 * @param pgpPrivKey
 */
public void generateTest(
    PGPSecretKeyRing sKey,
    PGPPublicKey     pgpPubKey,
    PGPPrivateKey    pgpPrivKey)
    throws Exception
{
    String                  data = "hello world!";
    ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
    ByteArrayInputStream    testIn = new ByteArrayInputStream(data.getBytes());
    PGPSignatureGenerator   sGen = new PGPSignatureGenerator(new BcPGPContentSignerBuilder(PublicKeyAlgorithmTags.DSA, HashAlgorithmTags.SHA1));

    sGen.init(PGPSignature.BINARY_DOCUMENT, pgpPrivKey);

    PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
    
    Iterator        it = sKey.getSecretKey().getPublicKey().getUserIDs();
    String          primaryUserID = (String)it.next();
    
    spGen.setSignerUserID(true, primaryUserID);
    
    sGen.setHashedSubpackets(spGen.generate());

    sGen.generateOnePassVersion(false).encode(bOut);

    PGPLiteralDataGenerator lGen = new PGPLiteralDataGenerator();
    
    Date testDate = new Date((System.currentTimeMillis() / 1000) * 1000);
    OutputStream lOut = lGen.open(
        new UncloseableOutputStream(bOut),
        PGPLiteralData.BINARY,
        "_CONSOLE",
        data.getBytes().length,
        testDate);

    int ch;
    while ((ch = testIn.read()) >= 0)
    {
        lOut.write(ch);
        sGen.update((byte)ch);
    }

    lGen.close();

    sGen.generate().encode(bOut);

    PGPObjectFactory        pgpFact = new PGPObjectFactory(bOut.toByteArray());

    PGPOnePassSignatureList p1 = (PGPOnePassSignatureList)pgpFact.nextObject();
    PGPOnePassSignature     ops = p1.get(0);
    
    PGPLiteralData          p2 = (PGPLiteralData)pgpFact.nextObject();
    if (!p2.getModificationTime().equals(testDate))
    {
        fail("Modification time not preserved");
    }

    InputStream             dIn = p2.getInputStream();

    ops.init(new BcPGPContentVerifierBuilderProvider(), pgpPubKey);
    
    while ((ch = dIn.read()) >= 0)
    {
        ops.update((byte)ch);
    }

    PGPSignatureList p3 = (PGPSignatureList)pgpFact.nextObject();

    if (!ops.verify(p3.get(0)))
    {
        fail("Failed generated signature check");
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:79,代码来源:BcPGPDSATest.java


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