Top Description Constructors Methods
org.bouncycastle.openpgp.examples

public Class ByteArrayHandler

extends Object
Class Inheritance
Imports
java.io.ByteArrayInputStream, .ByteArrayOutputStream, .IOException, .InputStream, .OutputStream, java.security.NoSuchProviderException, .SecureRandom, .Security, java.util.Date, org.bouncycastle.bcpg.ArmoredOutputStream, .CompressionAlgorithmTags, org.bouncycastle.jce.provider.BouncyCastleProvider, org.bouncycastle.openpgp.PGPCompressedData, .PGPCompressedDataGenerator, .PGPEncryptedDataGenerator, .PGPEncryptedDataList, .PGPException, .PGPLiteralData, .PGPLiteralDataGenerator, .PGPPBEEncryptedData, .PGPUtil, org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory, org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder, .JcePBEDataDecryptorFactoryBuilder, .JcePBEKeyEncryptionMethodGenerator, .JcePGPDataEncryptorBuilder, org.bouncycastle.util.io.Streams

Simple routine to encrypt and decrypt using a passphrase. This service routine provides the basic PGP services between byte arrays.

Note

this code plays no attention to -CONSOLE in the file name the specification of "_CONSOLE" in the filename. It also expects that a single pass phrase will have been used.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static byte[]
compress(byte[] clearData, String fileName, int algorithm)

public static byte[]

Returns:

Clear text as a byte array. I18N considerations are not handled by this routine
decrypt
(byte[]
The message to be decrypted.
encrypted
,
char[]
Pass phrase (key)
passPhrase
)

decrypt the passed in message stream

public static byte[]

Returns:

encrypted data.
encrypt
(byte[]
The test to be encrypted
clearData
,
char[]
The pass phrase (key). This method assumes that the key is a simple pass phrase, and does not yet support RSA or more sophisiticated keying.
passPhrase
,
String
File name. This is used in the Literal Data Packet (tag 11) which is really inly important if the data is to be related to a file to be recovered later. Because this routine does not know the source of the information, the caller can set something here for file name use that will be carried. If this routine is being used to encrypt SOAP MIME bodies, for example, use the file name from the MIME type, if applicable. Or anything else appropriate.
fileName
,
int algorithm, boolean armor)

Simple PGP encryptor between byte[].

public static void
main(String[] args)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ByteArrayHandlerback to summary
public ByteArrayHandler()

Method Detail

compressback to summary
private static byte[] compress(byte[] clearData, String fileName, int algorithm) throws IOException
decryptback to summary
public static byte[] decrypt(byte[] encrypted, char[] passPhrase) throws IOException, PGPException, NoSuchProviderException

decrypt the passed in message stream

Parameters
encrypted:byte[]

The message to be decrypted.

passPhrase:char[]

Pass phrase (key)

Returns:byte[]

Clear text as a byte array. I18N considerations are not handled by this routine

encryptback to summary
public static byte[] encrypt(byte[] clearData, char[] passPhrase, String fileName, int algorithm, boolean armor) throws IOException, PGPException, NoSuchProviderException

Simple PGP encryptor between byte[].

Parameters
clearData:byte[]

The test to be encrypted

passPhrase:char[]

The pass phrase (key). This method assumes that the key is a simple pass phrase, and does not yet support RSA or more sophisiticated keying.

fileName:String

File name. This is used in the Literal Data Packet (tag 11) which is really inly important if the data is to be related to a file to be recovered later. Because this routine does not know the source of the information, the caller can set something here for file name use that will be carried. If this routine is being used to encrypt SOAP MIME bodies, for example, use the file name from the MIME type, if applicable. Or anything else appropriate.

Returns:byte[]

encrypted data.

mainback to summary
public static void main(String[] args) throws Exception