|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--hcrypto.cipher.Cipher
This class provides the functionality for a wide range of historical ciphers that can be used for encryption and decryption.
To create a Cipher object, the application must call Cipher.getInstance() passing it a String that gives the name of the cipher algorithm. For example, here is how one would create a Caesar cipher.
Cipher cipher = Cipher.getInstance("Caesar"); HistoricalKey key = HistoricalKey.getInstance("Caesar", cipher.getProvider()); key.init("55/printable"); cipher.init(key); String c1encrypt = cipher.encrypt(secret);The Cipher.getInstance() method searches a list of providers for an implementation of Caesar cipher and will throw a "No such algorithm" exception if none is found. Details on creating an algorithm-dependent key for the cipher are described in the documentation of HistoricalKey class.
See also:
CipherEngine
HistoricalKey
Provider
Field Summary | |
protected java.lang.String |
algorithm
the name of this algorithm |
protected CipherEngine |
engine
provides a reference to the class that implements the cipher algorithm |
protected java.lang.String |
provider
the name of the provider of this algorithm |
Constructor Summary | |
protected |
Cipher(CipherEngine engine)
the constructor is only used internally to create a Cipher object. |
Method Summary | |
java.lang.String |
decrypt(java.lang.String s)
decrypts its String parameter returning the plaintext string. |
void |
decryptFile(java.lang.String inFileName,
java.lang.String outFileName)
decrypts a ciphertext input file into an output file by simply calling the engineDecryptFile() method implemented in the ENGINE. |
void |
decryptFile(java.lang.String inFileName,
java.lang.String outFileName,
java.lang.String encoding)
decrypts a ciphertext input file into an output file by simply calling the engineDecryptFile() method implemented in the ENGINE. |
java.lang.String |
encrypt(java.lang.String s)
encrypts its String parameter returning the encrypted string. |
void |
encryptFile(java.lang.String inFileName,
java.lang.String outFileName)
encrypts a plaintext input file into an output file by simply calling the engineEncryptFile() method implemented in the ENGINE. |
void |
encryptFile(java.lang.String inFileName,
java.lang.String outFileName,
java.lang.String encoding)
encrypts a plaintext input file into an output file by simply calling the engineEncryptFile() method implemented in the ENGINE. |
java.lang.String |
getAlgorithm()
returns a string giving the name of the cipher algorithm. |
java.lang.String |
getAlphabetRangeOptions()
returns a string giving the alphabet range options for a particular cipher. |
static Cipher |
getInstance(java.lang.String algorithm)
searches for a provider that provides an implementation of the algorithm named in its parameter, throwing a "no such algorithm" exception if none is found. |
static Cipher |
getInstance(java.lang.String algorithm,
java.lang.String provider)
searches for the provider named in the second parameter for an implementation of the algorithm named in its first parameter. |
java.lang.String |
getProvider()
returns a string giving the name of the provider that implements the cipher algorithm. |
void |
init(HistoricalKey key)
initializes the particular encrypting engine by calling the encapsulated CipherEngine and passing it a key of the appropriate type. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected CipherEngine engine
protected java.lang.String provider
protected java.lang.String algorithm
Constructor Detail |
protected Cipher(CipherEngine engine)
Method Detail |
public static final Cipher getInstance(java.lang.String algorithm, java.lang.String provider)
algorithm,
- a String giving the algorithm nameprovider,
- a String giving the provider namepublic static final Cipher getInstance(java.lang.String algorithm)
algorithm,
- a String giving the algorithm namepublic final void init(HistoricalKey key) throws java.lang.Exception
key,
- an instance of a HistoricalKeypublic final void encryptFile(java.lang.String inFileName, java.lang.String outFileName) throws java.lang.Exception
inFile,
- the name of the input plaintext file.outFile,
- the name of the output encrypted file.public final void encryptFile(java.lang.String inFileName, java.lang.String outFileName, java.lang.String encoding) throws java.lang.Exception
inFile,
- the name of the input plaintext file.outFile,
- the name of the output encrypted file.encoding,
- the name of the encoding scheme -- "ISO-2022-JP"public final void decryptFile(java.lang.String inFileName, java.lang.String outFileName) throws java.lang.Exception
inFile,
- the name of the input ciphertext file.outFile,
- the name of the output plaintext file.public final void decryptFile(java.lang.String inFileName, java.lang.String outFileName, java.lang.String encoding) throws java.lang.Exception
inFile,
- the name of the input ciphertext file.outFile,
- the name of the output plaintext file.encoding,
- the name of the encoding scheme -- e.g., "ISO-2022-JP"public java.lang.String encrypt(java.lang.String s) throws java.lang.Exception
s,
- a String to be encryptedpublic final java.lang.String decrypt(java.lang.String s) throws java.lang.Exception
s,
- a String to be decryptedpublic final java.lang.String getAlgorithm()
public final java.lang.String getProvider()
public final java.lang.String getAlphabetRangeOptions()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |