本文整理汇总了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" );
}
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
}
示例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() );
}
示例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();
}