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


Java JcaPGPObjectFactory.nextObject方法代码示例

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


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

示例1: doVerify

import org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory; //导入方法依赖的package包/类
private static void doVerify( JcaPGPObjectFactory objectFactory, PGPOnePassSignature onePassSignature )
        throws IOException, PGPException
{
    PGPSignatureList signatures = ( PGPSignatureList ) objectFactory.nextObject();

    if ( !onePassSignature.verify( signatures.get( 0 ) ) )
    {
        throw new PGPDataValidationException( "Signature verification failed" );
    }
}
 
开发者ID:subutai-io,项目名称:base,代码行数:11,代码来源:PGPVerify.java

示例2: getOnePassSignature

import org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory; //导入方法依赖的package包/类
private static PGPOnePassSignature getOnePassSignature( PGPPublicKey publicKey, JcaPGPObjectFactory pgpFact )
        throws IOException, PGPException
{
    PGPOnePassSignatureList p1 = ( PGPOnePassSignatureList ) pgpFact.nextObject();

    PGPOnePassSignature onePassSignature = p1.get( 0 );

    onePassSignature.init( new JcaPGPContentVerifierBuilderProvider().setProvider( "BC" ), publicKey );

    return onePassSignature;
}
 
开发者ID:subutai-io,项目名称:base,代码行数:12,代码来源:PGPVerify.java

示例3: decrypt

import org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory; //导入方法依赖的package包/类
public PGPDecryptionResult decrypt(InputStream in) throws IOException {

        PGPDecryptionResult result = new PGPDecryptionResult();
//        List<String> receivers = new ArrayList<>();

        in = org.bouncycastle.openpgp.PGPUtil.getDecoderStream(in);
        PGPObjectFactory pgpF = new PGPObjectFactory(in, new JcaKeyFingerprintCalculator());
        PGPEncryptedDataList enc;

        Object o = pgpF.nextObject();

        if (o instanceof  PGPEncryptedDataList) {
            enc = (PGPEncryptedDataList) o;
        } else {
            enc = (PGPEncryptedDataList) pgpF.nextObject();
        }

        Iterator it = enc.getEncryptedDataObjects();

        PGPPublicKeyEncryptedData pbe = null;

        while (it.hasNext()) {

            PGPPublicKeyEncryptedData current = (PGPPublicKeyEncryptedData) it.next();

            if(current.getKeyID() == secretKey.getKeyID()) {
                pbe = current;
            }

//            receivers.add(Long.toString(current.getKeyID()));
        }

        if(pbe == null)
            return result;


        try {
            PGPDigestCalculatorProvider digestCalculatorProvider = new JcaPGPDigestCalculatorProviderBuilder().build();

            PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(digestCalculatorProvider)
                    .build(passphrase.toCharArray());

            PGPPrivateKey privateKey = secretKey.extractPrivateKey(decryptor);

            InputStream clear = pbe.getDataStream(new JcePublicKeyDataDecryptorFactoryBuilder().setProvider("BC").build(privateKey));


            JcaPGPObjectFactory plainFact = new JcaPGPObjectFactory(clear);
            Object message = plainFact.nextObject();

            if(message instanceof PGPCompressedData) {
                PGPCompressedData   cData = (PGPCompressedData)plainFact.nextObject();

                InputStream         compressedStream = new BufferedInputStream(cData.getDataStream());
                JcaPGPObjectFactory    pgpFact = new JcaPGPObjectFactory(compressedStream);

                message = pgpFact.nextObject();
            }

            if (message instanceof PGPLiteralData)
            {
                PGPLiteralData ld = (PGPLiteralData)message;

                InputStream unc = ld.getInputStream();

                ObjectMapper mapper = new ObjectMapper();
                result.submission = mapper.readValue(unc, Submission.class);
                unc.close();
                Log.i(result.submission.reply_to);
                Log.i(Integer.toString(result.submission.receivers.size()));

                result.decryptedSuccessfully = !pbe.isIntegrityProtected() ||  pbe.verify();
                return result;
            }
        } catch (PGPException e) {
            e.printStackTrace();
        }
        return result;
    }
 
开发者ID:Tethik,项目名称:whistleblower,代码行数:80,代码来源:CryptographyHandler.java

示例4: verifyClearSign

import org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory; //导入方法依赖的package包/类
public static boolean verifyClearSign( byte[] message, PGPPublicKeyRing pgpRings )
        throws IOException, PGPException, SignatureException
{
    ArmoredInputStream aIn = new ArmoredInputStream( new ByteArrayInputStream( message ) );
    ByteArrayOutputStream bout = new ByteArrayOutputStream();


    //
    // write out signed section using the local line separator.
    // note: trailing white space needs to be removed from the end of
    // each line RFC 4880 Section 7.1
    //
    ByteArrayOutputStream lineOut = new ByteArrayOutputStream();

    boolean isFirstLineClearText = aIn.isClearText();
    int lookAhead = readInputLine( lineOut, aIn );

    if ( lookAhead != -1 && isFirstLineClearText )
    {
        bout.write( lineOut.toByteArray() );
        while ( lookAhead != -1 && aIn.isClearText() )
        {
            lookAhead = readInputLine( lineOut, lookAhead, aIn );
            bout.write( lineOut.toByteArray() );
        }
    }

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


    PGPPublicKey publicKey = pgpRings.getPublicKey( sig.getKeyID() );
    sig.init( new JcaPGPContentVerifierBuilderProvider().setProvider( "BC" ), publicKey );

    //
    // read the input, making sure we ignore the last newline.
    //

    InputStream sigIn = new ByteArrayInputStream( bout.toByteArray() );

    lookAhead = readInputLine( lineOut, sigIn );

    processLine( sig, lineOut.toByteArray() );

    if ( lookAhead != -1 )
    {
        do
        {
            lookAhead = readInputLine( lineOut, lookAhead, sigIn );

            sig.update( ( byte ) '\r' );
            sig.update( ( byte ) '\n' );

            processLine( sig, lineOut.toByteArray() );
        }
        while ( lookAhead != -1 );
    }

    sigIn.close();

    return sig.verify();
}
 
开发者ID:subutai-io,项目名称:base,代码行数:64,代码来源:PGPEncryptionUtil.java

示例5: getInputStream

import org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory; //导入方法依赖的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.jcajce.JcaPGPObjectFactory; //导入方法依赖的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.jcajce.JcaPGPObjectFactory; //导入方法依赖的package包/类
public String verifySignature(String message)
        throws PGPInvalidSignatureException, PGPSignatureVerificationException {

    try {
        ArmoredInputStream aIn = new ArmoredInputStream(new ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)));

        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        int ch;

        while ((ch = aIn.read()) >= 0 && aIn.isClearText()) {
            bOut.write((byte) ch);
        }

        JcaPGPObjectFactory pgpFact = new JcaPGPObjectFactory(aIn);
        PGPSignatureList p3 = (PGPSignatureList) pgpFact.nextObject();
        checkState(p3 != null && p3.size() >= 1, "No signatures");
        PGPSignature sig = p3.get(0);

        sig.init(new BcPGPContentVerifierBuilderProvider(), publicKey.getSigningKey());

        ByteArrayOutputStream lineOut = new ByteArrayOutputStream();
        byte[] content = bOut.toByteArray();
        InputStream sigIn = new ByteArrayInputStream(content);
        int lookAhead = readInputLine(lineOut, sigIn);

        processLine(sig, lineOut.toByteArray());

        if (lookAhead != -1) {
            do {
                lookAhead = readInputLine(lineOut, lookAhead, sigIn);

                sig.update((byte) '\r');
                sig.update((byte) '\n');

                processLine(sig, lineOut.toByteArray());
            } while (lookAhead != -1);
        }

        if (sig.verify()) {
            return new String(content, StandardCharsets.UTF_8);
        }

        throw new PGPInvalidSignatureException(
                "Invalid signature, received keyId=" + Long.toHexString(sig.getKeyID()).toUpperCase()
        );

    } catch (IOException | PGPException e) {
        throw new PGPSignatureVerificationException("Error verifying message", e);
    }
}
 
开发者ID:quedexnet,项目名称:java-api,代码行数:51,代码来源:BcSignatureVerifier.java

示例8: getObjectFactory

import org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory; //导入方法依赖的package包/类
private static JcaPGPObjectFactory getObjectFactory( byte signedData[] ) throws IOException, PGPException
{
    InputStream in = PGPUtil.getDecoderStream( new ByteArrayInputStream( signedData ) );

    JcaPGPObjectFactory pgpFact = new JcaPGPObjectFactory( in );

    PGPCompressedData compressedData = ( PGPCompressedData ) pgpFact.nextObject();

    return new JcaPGPObjectFactory( compressedData.getDataStream() );
}
 
开发者ID:subutai-io,项目名称:base,代码行数:11,代码来源:PGPVerify.java

示例9: getPGPEncryptedData

import org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory; //导入方法依赖的package包/类
private static PGPPublicKeyEncryptedData getPGPEncryptedData( byte data[] ) throws IOException
{
    InputStream in = PGPUtil.getDecoderStream( new ByteArrayInputStream( data ) );

    JcaPGPObjectFactory objectFactory = new JcaPGPObjectFactory( in );

    PGPEncryptedDataList encryptedDataList = ( PGPEncryptedDataList ) objectFactory.nextObject();

    Iterator it = encryptedDataList.getEncryptedDataObjects();

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


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