| Cipher |
|
typedict |
| |
A
Cipher
is a text encryption and decryption object.
It can use a variety of cryptographic
algorithms to achieve its purpose.
Access to certain algorithms may require loading additional provider
class files.
Yoix programs interact with this object
by reading or writing the following
Cipher
fields:
| algorithm |
A read-only
String
that provides the name of the algorithm, as defined by the provider, used by the cipher for
encryption and decryption.
| | initializer |
After a
specification
is supplied for a
Cipher,
it needs to be initialized by assigning a value to this field.
The several possibilties are a
String
that represents a keystring, which has been described elsewhere, a
Certificate
object or a
Dictionary
object, which should contain a
certificate
(Certificate)
or
key
(String
or
Key)
field and, possibly, a
random
(Random)
field.
If a
Key
object is spplied for the
key
field in the dictionary, then an
int
field called
keytype
with a value of
PUBLIC_KEY
or
PRIVATE_KEY
is required.
| | opmode |
An
int
that sets the mode of the cipher to
ENCRYPT_MODE
or
DECRYPT_MODE.
| | parameters |
A read-only
Dictionary
summarizing the algorithm parameters used by the cipher.
| | provider |
A read-only
Dictionary
summarizing all the information related to the provider of the cipher algorithm.
| | specification |
Either a
String
specifying the algorithm or transformation (see format below) to be used by the cipher or a
Dictionary
providing a more detailed information.
Common dictionary fields are:
| mode |
A
String
for specifying the mode of the algorithm.
A value supplied here will override one supplied as part of the
transformation
field.
| | padding |
A
String
for specifying the padding of the algorithm.
A value supplied here will override one supplied as part of the
transformation
field.
| | provider |
A
String
specifying the provider of the cipher algorithm.
| | transformation |
A
String
giving the name of the algorithm to use for key generation or the
algorithm name, mode and padding to be used for key generation in the form
This value must be present and non-null within the dictionary.
algorithm/mode/padding.
|
| | text |
When
opmode
is
ENCRYPT_MODE,
this field is used to accomplish encryption by writing one ore more cleartext
String
values to it and subsequently reading from it an
Array
of
int
elements, each representing a byte of ciphertext.
When
opmode
is
DECRYPT_MODE,
this field is used to accomplish decryption by writing to it one ore more
Array
values containing
int
elements, each representing a byte of ciphertext, or, alternatively, writing to it one or more
String
values of hex-encoded ciphertext bytes and subsequently reading from it a
String
of cleartext.
|
Several permanent fields have not been documented and should not be
used in Yoix applications.
| |
| Example: |
The program,
import yoix.*.*;
Key key = {
Dictionary specification = {
int type = SYMMETRIC_KEY;
String transformation = "DES";
};
};
Cipher cipher = {
String specification = "DES";
int opmode = ENCRYPT_MODE;
String initializer = key.keystring();
};
cipher.text = "Try encrypting ";
cipher.text = "this text.";
Array encrypted = cipher.text;
String hexed = btoh(encrypted);
fprintf(stdout, "Encrypted text:\n%s\n\n", hexed);
cipher.opmode = DECRYPT_MODE;
cipher.text = encrypted;
fprintf(stdout, "Decrypted text (from array):\n%s\n\n", cipher.text);
cipher.text = hexed;
fprintf(stdout, "Decrypted text (from hex string):\n%s\n\n",
cipher.text);
creates a symmetric
Key
and uses it to initialize a
Cipher.
The cipher is then used to encrypt a few text strings and then decrypt the text.
The text to decrypt can be in either byte array or hex-encdoded string format.
The
btoh
built-in is used to convert the ciphertext byte array into a hex-encoded string.
| | |
| See Also: |
adjustSecurity,
btoh,
Certificate,
Key,
KeyStore,
Random
|
|
Yoix is a registered trademark of AT&T Inc.
|