May 1998
Intermediate to advanced
362 pages
10h 8m
English
Class javax.crypto.Cipher
This class represents a cryptographic cipher, either symmetric or
asymmetric. To get a cipher for a particular algorithm, call one of
the getInstance() methods. You should specify an
algorithm name, a cipher mode, and a padding scheme. The cipher
should be initialized for encryption or decryption using the
init() method and an appropriate key. To actually
perform the encryption or decryption, use update()
and doFinal(). The following example shows how to
encrypt plaintext using a DES cipher in ECB mode with PKCS#5 padding:
public byte[] simpleEncrypt(byte[] plaintext, Key key) throws Exception
{
Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] ciphertext = cipher.doFinal(stringBytes);
return ciphertext;
}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(); ...
Read now
Unlock full access