Examples of ArmoredOutputStream


Examples of org.bouncycastle.bcpg.ArmoredOutputStream

        boolean         withIntegrityCheck)
        throws IOException, NoSuchProviderException
    {
        if (armor)
        {
            out = new ArmoredOutputStream(out);
        }

        try
        {
            byte[] compressedData = PGPExampleUtil.compressFile(fileName, CompressionAlgorithmTags.ZIP);
View Full Code Here

Examples of org.bouncycastle.bcpg.ArmoredOutputStream

        boolean         armor)
        throws IOException, InvalidKeyException, NoSuchProviderException, SignatureException, PGPException
    {
        if (armor)
        {
            secretOut = new ArmoredOutputStream(secretOut);
        }

        PGPKeyPair        dsaKeyPair = new PGPKeyPair(PGPPublicKey.DSA, dsaKp, new Date());
        PGPKeyPair        elgKeyPair = new PGPKeyPair(PGPPublicKey.ELGAMAL_ENCRYPT, elgKp, new Date());
        PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
        PGPKeyRingGenerator    keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, dsaKeyPair,
                 identity, sha1Calc, null, null, new JcaPGPContentSignerBuilder(dsaKeyPair.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1), new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256, sha1Calc).setProvider("BC").build(passPhrase));
       
        keyRingGen.addSubKey(elgKeyPair);
       
        keyRingGen.generateSecretKeyRing().encode(secretOut);
       
        secretOut.close();
       
        if (armor)
        {
            publicOut = new ArmoredOutputStream(publicOut);
        }
       
        keyRingGen.generatePublicKeyRing().encode(publicOut);
       
        publicOut.close();
View Full Code Here

Examples of org.bouncycastle.bcpg.ArmoredOutputStream

            spGen.setSignerUserID(false, (String)it.next());
            sGen.setHashedSubpackets(spGen.generate());
        }
       
        ByteArrayOutputStream  bOut = new ByteArrayOutputStream();
        ArmoredOutputStream    aOut = new ArmoredOutputStream(bOut);
        ByteArrayInputStream   bIn = new ByteArrayInputStream(message.getBytes());

        aOut.beginClearText(PGPUtil.SHA256);

        //
        // note the last \n in the file is ignored
        //
        ByteArrayOutputStream lineOut = new ByteArrayOutputStream();
        int lookAhead = readInputLine(lineOut, bIn);

        processLine(aOut, sGen, lineOut.toByteArray());

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

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

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

        aOut.endClearText();

        BCPGOutputStream            bcpgOut = new BCPGOutputStream(aOut);

        sGen.generate().encode(bcpgOut);

        aOut.close();
       
        messageTest(new String(bOut.toByteArray()), type);
    }
View Full Code Here

Examples of org.bouncycastle.bcpg.ArmoredOutputStream

    PGPSigner signer = signingConfiguration.getSigner();
    PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator(new BcPGPContentSignerBuilder(signer.getSecretKey().getPublicKey().getAlgorithm(), PGPUtil.SHA1));
    signatureGenerator.init(PGPSignature.BINARY_DOCUMENT, signer.getPrivateKey());

    BCPGOutputStream out = new BCPGOutputStream(new ArmoredOutputStream(baos));
    signatureGenerator.update(release);
    signatureGenerator.generate().encode(out);

    out.close();
    baos.close();
View Full Code Here

Examples of org.bouncycastle.bcpg.ArmoredOutputStream

    // Extract the key and return it
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PGPSigner signer = configuration.getSigner();
    PGPPublicKey publicKey = signer.getSecretKey().getPublicKey();

    BCPGOutputStream out = new BCPGOutputStream(new ArmoredOutputStream(baos));
    publicKey.encode(out);

    out.close();
    baos.close();
View Full Code Here

Examples of org.bouncycastle.bcpg.ArmoredOutputStream

        int digest = PGPUtil.SHA1;
       
        PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator(new BcPGPContentSignerBuilder(privateKey.getPublicKeyPacket().getAlgorithm(), digest));
        signatureGenerator.init(PGPSignature.CANONICAL_TEXT_DOCUMENT, privateKey);
       
        ArmoredOutputStream armoredOutput = new ArmoredOutputStream(output);
        armoredOutput.beginClearText(digest);
       
        BufferedReader reader = new BufferedReader(new InputStreamReader(input));
       
        String line;
        while ((line = reader.readLine()) != null) {
            // trailing spaces must be removed for signature calculation (see http://tools.ietf.org/html/rfc4880#section-7.1)
            byte[] data = trim(line).getBytes("UTF-8");
           
            armoredOutput.write(data);
            armoredOutput.write(EOL);
           
            signatureGenerator.update(data);
            signatureGenerator.update(EOL);
        }

        armoredOutput.endClearText();
       
        PGPSignature signature = signatureGenerator.generate();
        signature.encode(new BCPGOutputStream(armoredOutput));
       
        armoredOutput.close();
    }
View Full Code Here

Examples of org.bouncycastle.bcpg.ArmoredOutputStream

   
    public String generateASCIISignature() throws SignatureException, PGPException {
        try {
            PGPSignature signature = generateSignature();
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            ArmoredOutputStream armorStream = new ArmoredOutputStream(buffer);
            signature.encode(armorStream);
            armorStream.close();
            return new String(buffer.toByteArray());
        } catch(IOException e) {
            //Should never happen since we are just using a memory buffer
            throw new RuntimeException(e);
        }
View Full Code Here

Examples of org.bouncycastle.bcpg.ArmoredOutputStream

        }

        InputStream input = ExchangeHelper.convertToMandatoryType(exchange, InputStream.class, graph);

        if (armored) {
            outputStream = new ArmoredOutputStream(outputStream);
        }

        PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(PGPEncryptedData.CAST5, integrity, new SecureRandom(), "BC");
        encGen.addMethod(key);
        OutputStream encOut = encGen.open(outputStream, new byte[BUFFER_SIZE]);
View Full Code Here

Examples of org.bouncycastle.bcpg.ArmoredOutputStream

            IOUtils.closeQuietly(plaintextStream);
        }
        byte[] compressedData = PGPDataFormatUtil.compress(plaintextData, PGPLiteralData.CONSOLE, CompressionAlgorithmTags.ZIP);

        if (armored) {
            outputStream = new ArmoredOutputStream(outputStream);
        }

        PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(PGPEncryptedData.CAST5, integrity, new SecureRandom(), "BC");
        encGen.addMethod(key);
View Full Code Here

Examples of org.bouncycastle.bcpg.ArmoredOutputStream

        boolean         withIntegrityCheck)
        throws IOException, NoSuchProviderException
    {   
        if (armor)
        {
            out = new ArmoredOutputStream(out);
        }
       
        try
        {
            ByteArrayOutputStream       bOut = new ByteArrayOutputStream();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.