Java Code Examples for org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory#nextObject()
The following examples show how to use
org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory#nextObject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PGPVerify.java From peer-os with Apache License 2.0 | 5 votes |
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" ); } }
Example 2
Source File: PGPVerify.java From peer-os with Apache License 2.0 | 5 votes |
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; }
Example 3
Source File: PGPVerify.java From peer-os with Apache License 2.0 | 4 votes |
private static InputStream getInputStream( JcaPGPObjectFactory objectFactory ) throws IOException { PGPLiteralData literalData = ( PGPLiteralData ) objectFactory.nextObject(); return literalData.getInputStream(); }
Example 4
Source File: PGPDecrypt.java From peer-os with Apache License 2.0 | 4 votes |
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(); }
Example 5
Source File: PGPEncryptionUtil.java From peer-os with Apache License 2.0 | 4 votes |
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(); }
Example 6
Source File: PGPVerify.java From peer-os with Apache License 2.0 | 3 votes |
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() ); }
Example 7
Source File: PGPDecrypt.java From peer-os with Apache License 2.0 | 3 votes |
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(); }