Book Home Java Security Search this book

D.5. Package javax.crypto

Class javax.crypto.Cipher

This engine class represents a cryptographic cipher, either symmetric or asymmetric. To get a cipher for a particular algorithm, call one of the getInstance() methods, specifying an algorithm name, a cipher mode, and a padding scheme. The cipher should be initialized for encryption or decryption using an init() method and an appropriate key (and, optionally, a set of algorithm-specific parameters, though these are typically unused). Then you can perform the encryption or decryption, using the update() and doFinal() methods.

Class Definition

public class javax.crypto.Cipher
	extends java.lang.Object {

	// Constants
	public static final int DECRYPT_MODE;
	public static final int ENCRYPT_MODE;

	// Constructors
	protected Cipher(CipherSpi, Provider, String);

	// Class Methods
	public static final Cipher getInstance(String);
	public static final Cipher getInstance(String, String);

	// Instance Methods
	public final byte[] doFinal();
	public final byte[] doFinal(byte[]);
	public final int doFinal(byte[], int);
	public final byte[] doFinal(byte[], int, int);
	public final int doFinal(byte[], int, int, byte[]);
	public final int doFinal(byte[], int, int, byte[], int);
	public final int getBlockSize();
	public final byte[] getIV();
	public final int getOutputSize(int);
	public final AlgorithmParameters getParameters();
	public final Provider getProvider();
	public final void init(int, Key);
	public final void init(int, Key, SecureRandom);
	public final void init(int, Key, AlgorithmParameterSpec);
	public final void init(int, Key, AlgorithmParameterSpec,
							SecureRandom);
	public final void init(int, Key, AlgorithmParameters);
	public final void init(int, Key, AlgorithmParameters, 
                           SecureRandom);
	public final byte[] update(byte[]);
	public final byte[] update(byte[], int, int);
	public final int update(byte[], int, int, byte[]);
	public final int update(byte[], int, int, byte[], int);
}

See also: AlgorithmParameterSpec, CipherSpi, Key, Provider, SecureRandom

Class javax.crypto.CipherInputStream

A cipher input stream is a filter stream that passes its data through a cipher. You can construct a cipher input stream by specifying an underlying stream and supplying an initialized cipher. For best results, use a byte-oriented cipher mode with this stream.

Class Definition

public class javax.crypto.CipherInputStream
	extends java.io.FilterInputStream {

	// Constructors
	protected CipherInputStream(InputStream);
	public CipherInputStream(InputStream, Cipher);

	// Instance Methods
	public int available();
	public void close();
	public boolean markSupported();
	public int read();
	public int read(byte[]);
	public int read(byte[], int, int);
	public long skip(long);
}

See also: Cipher

Class javax.crypto.CipherOutputStream

This class is a filter output stream that passes all its data through a cipher. You can construct a cipher output stream by specifying an underlying output stream and an initialized cipher. For best results, use a byte-oriented mode for the cipher.

Class Definition

public class javax.crypto.CipherOutputStream
	extends java.io.FilterOutputStream {

	// Constructors
	protected CipherOutputStream(OutputStream);
	public CipherOutputStream(OutputStream, Cipher);

	// Instance Methods
	public void close();
	public void flush();
	public void write(int);
	public void write(byte[]);
	public void write(byte[], int, int);
}

See also: Cipher

Class javax.crypto.CipherSpi

This class is the Security Provider Interface of the Cipher class. To implement a particular cipher algorithm, create a subclass of this class and register the class with an appropriate security provider. Like all SPI classes, the methods that begin with engine are called by their corresponding method (without engine) from the Cipher class.

Class Definition

public abstract class javax.crypto.CipherSpi
	extends java.lang.Object {

	// Constructors
	public CipherSpi();

	// Protected Instance Methods
	protected abstract byte[] engineDoFinal(byte[], int, int);
	protected abstract int engineDoFinal(byte[], int, int,
									byte[], int);
	protected abstract int engineGetBlockSize();
	protected abstract byte[] engineGetIV();
	protected abstract int engineGetOutputSize(int);
	protected abstract void engineInit(int, Key, SecureRandom);
	protected abstract void engineInit(int, Key, 
					AlgorithmParameterSpec, SecureRandom);
	protected abstract void engineInit(int, Key, AlgorithmParameters,
								 SecureRandom);
	protected abstract void engineSetMode(String);
	protected abstract void engineSetPadding(String);
	protected abstract byte[] engineUpdate(byte[], int, int);
	protected abstract int engineUpdate(byte[], int, int, byte[], int);
}

See also: AlgorithmParameterSpec, Cipher, Key, SecureRandom

Class javax.crypto.KeyAgreement

This engine class represents a key agreement protocol, which is an arrangement by which two parties can agree on a secret value. You can obtain an instance of this class by calling the getInstance() method. After initializing the object (see init()), you can step through the phases of the key agreement protocol using the doPhase() method. Once the phases are complete, the secret value (that is, the key) is returned from the generateSecret() method.

Class Definition

public class javax.crypto.KeyAgreement
	extends java.lang.Object {

	// Constructors
	protected KeyAgreement(KeyAgreementSpi, Provider, String);

	// Class Methods
	public static final KeyAgreement getInstance(String);
	public static final KeyAgreement getInstance(String, String);

	// Instance Methods
	public final Key doPhase(Key, boolean);
	public final byte[] generateSecret();
	public final int generateSecret(byte[], int);
	public final String getAlgorithm();
	public final Provider getProvider();
	public final void init(Key);
	public final void init(Key, SecureRandom);
	public final void init(Key, AlgorithmParameterSpec);
	public final void init(Key, AlgorithmParameterSpec, SecureRandom);
}

See also: AlgorithmParameterSpec, Key, KeyAgreementSpi, Provider, SecureRandom

Class javax.crypto.KeyAgreementSpi

This is the Security Provider Interface class for the KeyAgreement class. If you want to implement a key agreement algorithm, create a subclass of this class and register it with an appropriate security provider.

Class Definition

public abstract class javax.crypto.KeyAgreementSpi
	extends java.lang.Object {

	// Constructors
	public KeyAgreementSpi();

	// Protected Instance Methods
	protected abstract Key engineDoPhase(Key, boolean);
	protected abstract byte[] engineGenerateSecret();
	protected abstract int engineGenerateSecret(byte[], int);
	protected abstract void engineInit(Key, SecureRandom);
	protected abstract void engineInit(Key, AlgorithmParameterSpec,
									SecureRandom);
}

See also: AlgorithmParameterSpec, Key, KeyAgreement, SecureRandom

Class javax.crypto.KeyGenerator

A key generator creates secret keys for use with symmetric ciphers. Key generators are obtained by calling the getInstance() method; they must then be initialized with an init() method. The key itself is then returned from the generateSecret() method.

Class Definition

public class javax.crypto.KeyGenerator
	extends java.lang.Object {

	// Constructors
	protected KeyGenerator(KeyGeneratorSpi, Provider, String);

	// Class Methods
	public static final KeyGenerator getInstance(String);
	public static final KeyGenerator getInstance(String, String);

	// Instance Methods
	public final SecretKey generateKey();
	public final String getAlgorithm();
	public final Provider getProvider();
	public final void init(int);
	public final void init(int, SecureRandom);
	public final void init(SecureRandom);
	public final void init(AlgorithmParameterSpec);
	public final void init(AlgorithmParameterSpec, SecureRandom);
}

See also: AlgorithmParameterSpec, KeyGeneratorSpi, Provider, SecretKey, SecureRandom

Class javax.crypto.KeyGeneratorSpi

This is the Security Provider Interface for the KeyGenerator class. To create an implementation of a key generation algorithm, make a subclass of this class and register the implementation with an appropriate security provider.

Class Definition

public abstract class javax.crypto.KeyGeneratorSpi
	extends java.lang.Object {

	// Constructors
	public KeyGeneratorSpi();

	// Protected Instance Methods
	protected abstract SecretKey engineGenerateKey();
	protected abstract void engineInit(int, SecureRandom);
	protected abstract void engineInit(SecureRandom);
	protected abstract void engineInit(AlgorithmParameterSpec,
								SecureRandom);
}

See also: AlgorithmParameterSpec, KeyGenerator, SecretKey, SecureRandom

Class javax.crypto.NullCipher

As its name implies, null cipher is a cipher that does nothing. You can use it to test cryptographic programs. Since a null cipher performs no transformations, its ciphertext will be exactly the same as its plaintext.

Class Definition

public class javax.crypto.NullCipher
	extends javax.crypto.Cipher {

	// Constructors
	public NullCipher();
}

See also: Cipher

Class javax.crypto.SealedObject

A sealed object is a container for another object. The contained object is serialized and then encrypted using a cipher. You can construct a sealed object using any serializable object and a cipher that is initialized for encryption. To decrypt the contained object, call the getObject() method with a cipher that is initialized for decryption.

Class Definition

public class javax.crypto.SealedObject
	extends java.lang.Object
	implements java.io.Serializable {

	// Constructors
	public SealedObject(Serializable, Cipher);

	// Instance Methods
	public final Object getObject(Cipher);
	public final Object getObject(Key);
	public final Object getObject(Key, String);
}

See also: PublicKey, PrivateKey

Interface javax.crypto.SecretKey

A secret key represents a key that is used with a symmetric cipher. This interface is used strictly for type identification.

Interface Definition

public abstract interface javax.crypto.SecretKey
	implements java.security.Key {
}

See also: Key

Class javax.crypto.SecretKeyFactory

A secret key factory is used to convert between secret key data formats; like a key factory, this is typically used to import a key based on its external format or to export a key to its encoded format or algorithm parameters. Instances of this class are obtained by calling the getInstance() method. Keys may be exported by using the translateKey() method; they are imported by using the generate Secret() method.

Class Definition

public class javax.crypto.SecretKeyFactory
	extends java.lang.Object {

	// Constructors
	protected SecretKeyFactory(SecretKeyFactorySpi, Provider);

	// Class Methods
	public static final SecretKeyFactory getInstance(String);
	public static final SecretKeyFactory getInstance(String, String);

	// Instance Methods
	public final SecretKey generateSecret(KeySpec);
	public final KeySpec getKeySpec(SecretKey, Class);
	public final Provider getProvider();
	public final SecretKey translateKey(SecretKey);
}

See also: KeySpec, Provider, SecretKey, SecretKeyFactorySpi

Class javax.crypto.SecretKeyFactorySpi

This class is the Security Provider Interface for the SecretKeyFactory class. To create a secret key factory, make a subclass of this class and register your implementation with an appropriate provider.

Class Definition

public abstract class javax.crypto.SecretKeyFactorySpi
	extends java.lang.Object {

	// Constructors
	public SecretKeyFactorySpi();

	// Protected Instance Methods
	protected abstract SecretKey engineGenerateSecret(KeySpec);
	protected abstract KeySpec engineGetKeySpec(SecretKey, Class);
	protected abstract SecretKey engineTranslateKey(SecretKey);
}

See also: KeySpec, Provider, SecretKey, SecretKeyFactory



Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.

This HTML Help has been published using the chm2web software.