PGPEncryptionUtil { public static byte[] armorByteArray( byte[] data ) throws PGPException { try { ByteArrayOutputStream encOut = new ByteArrayOutputStream(); ArmoredOutputStream armorOut = new ArmoredOutputStream( encOut ); armorOut.write( data ); armorOut.flush(); armorOut.close(); return encOut.toByteArray(); } catch ( Exception e ) { throw new PGPException( "Error loading keyring", e ); } } private  PGPEncryptionUtil(); static byte[] encrypt( final byte[] message, final PGPPublicKey publicKey, boolean armored ); static byte[] decrypt( final byte[] encryptedMessage, final PGPSecretKeyRing secretKeyRing,
                                  final String secretPwd ); static byte[] decrypt( final byte[] encryptedMessage, final InputStream secretKeyRing,
                                  final String secretPwd ); static boolean verifySignature( ContentAndSignatures contentAndSignatures, PGPPublicKey publicKey ); static ContentAndSignatures decryptAndReturnSignatures( final byte[] encryptedMessage,
                                                                   final PGPSecretKeyRing secretKeyRing,
                                                                   final String secretPwd ); static byte[] decryptAndVerify( byte[] encryptedMessage, final PGPSecretKey secretKey,
                                           final String secretPwd, final PGPPublicKey publicKey ); static byte[] signAndEncrypt( final byte[] message, final PGPSecretKey secretKey, final String secretPwd,
                                         final PGPPublicKey publicKey, final boolean armored ); static KeyPair generateKeyPair( String userId, String secretPwd, boolean armored ); static String BytesToHex( byte[] bytes ); static byte[] armorByteArray( byte[] data ); static boolean verify( byte[] signedMessage, PGPPublicKey publicKey ); static byte[] sign( byte[] message, PGPSecretKey secretKey, String secretPwd, boolean armor ); static byte[] extractContentFromClearSign( byte[] signedMessage ); static boolean verifyClearSign( byte[] message, PGPPublicKeyRing pgpRings ); static byte[] clearSign( byte[] message, PGPSecretKey pgpSecKey, char[] pass, String digestName ); static PGPPublicKey findPublicKeyById( InputStream publicKeyRing, String keyId ); static PGPPublicKey findPublicKeyByFingerprint( InputStream publicKeyRing, String fingerprint ); static PGPSecretKey findSecretKeyById( InputStream secretKeyRing, String keyId ); static PGPSecretKey findSecretKeyByFingerprint( InputStream secretKeyRing, String fingerprint ); static X509Certificate getX509CertificateFromPgpKeyPair( PGPPublicKey pgpPublicKey,
                                                                    PGPSecretKey pgpSecretKey, String secretPwd,
                                                                    String issuer, String subject, Date dateOfIssue,
                                                                    Date dateOfExpiry, BigInteger serial ); static PGPPrivateKey getPrivateKey( final PGPSecretKey secretKey, final String secretPwd ); static String armorByteArrayToString( byte[] data ); static PGPPublicKeyRing signPublicKey( PGPPublicKeyRing publicKeyRing, String id, PGPSecretKey secretKey,
                                                  String secretKeyPassword ); static boolean verifyPublicKey( PGPPublicKey keyToVerify, String id, PGPPublicKey keyToVerifyWith ); static PGPPublicKeyRing removeSignature( PGPPublicKeyRing keyToRemoveFrom, String id ); static PGPPublicKeyRing removeSignature( PGPPublicKeyRing keyToRemoveFrom,
                                                    PGPPublicKey keySignatureToRemove );  }
@Test public void testArmorByteArray() throws Exception { String armored = new String( PGPEncryptionUtil.armorByteArray( "test".getBytes() ) ); assertThat( armored, startsWith( "-----BEGIN PGP MESSAGE-----" ) ); }