AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YChart | YDAT | YWAIT | Byzgraf | FAQs
Key typedict
 
A Key is a cryptographic key generator object. It can generate symmetric (a.k.a., secure) and asymmetric (a.k.a., public/private key pair) keys using a variety of cryptographic algorithms. Access to certain algorithms may require loading additional class files through a provider such as BouncyCastle.org. Yoix programs interact with these key generators by reading, writing or executing the following Key fields:
algorithm A read-only String that provides the name of the algorithm, as defined by the provider, used to generate the key.
key A read-only Dictionary that contains representations of the key's bytes. For a symmetric key, the Dictionary will contain fields called secret_bytes, which is an Array of int values representing the encoded bytes of the key, and secret_text, which is a String of the key bytes in hex-encoded format using two hex characters per byte. For an asymmetric key, the Dictionary contains fields that describe both the public key component and the private key component in a manner similar to that used for a symmetric key. In this case, the fields are called public_bytes, private_bytes, public_text and private_text.
keystring([int type]) A Builtin that returns a String that can be used by other Yoix operations requiring a key. Although the string is both hex-encoded and encrypted, it should be considered as insecure as clear text and merely serves to hide pertinent information from only the most casual and incurious of observers. In addition to the key bytes, the string also encodes the key type and the name of the key algorithm. An int argument can be used to specify for which key type a string should be genreated. For a symmetric key, there is one choice for key type and supplying no argument is equivalent to specifying SECRET_KEY. For an asymmetric key pair, supplying no argument is equivalent to specifying PUBLIC_KEY. The private key component must be specifically requested by specifying PRIVATE_KEY.
parameters A read-only Dictionary summarizing the algorithm parameters used for generating the key.
provider A read-only Dictionary summarizing all the information related to the provider of this key algorithm.
specification A Dictionary used to specify the key generation algorithm. Common component fields are:
keysize An int specifying the size of a generated key in bytes.
provider A String specifying the algorithm provider to use when generating keys.
random A secure Random that will be used when generating keys.
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.
type An int representing the key type, which would be either ASYMMETRIC_KEY or SYMMETRIC_KEY. This value must be present and non-null within the dictionary.
Several permanent fields have not been documented and should not be used in Yoix applications.

 
 Example:   The program,
import yoix.*.*;

Key k = {
    Dictionary specification = {
	int type = SYMMETRIC_KEY;
	String transformation = "DES";
    };
};

Cipher c = {
    String specification = "DES";
    int opmode = ENCRYPT_MODE;
    String initializer = k.keystring();
};

c.text = "Try encrypting this text.";

Array encrypted = c.text;

c.opmode = DECRYPT_MODE;
c.text = encrypted;

fprintf(stdout, "Encrypted text:\n%s\n\n", btoh(encrypted));
fprintf(stdout, "Decrypted text:\n%s\n\n", c.text);
creates a symmetric key that is used by a Cipher object to encrypt and decrypt some text. This next example is much the same except that it creates an asymmetric key pair. Its public key is used by a Cipher to encrypt some text and its private key is used by another Cipher to decrypt it. Since the standard Java distribution does not include the algorithms for constructing asymmetric keys, the example uses the BouncyCastle package available at bouncycastle.org as the provider.
import yoix.*.*;

String bcjarfile = "Data/bcprov-jdk14-129.jar";
String fullpath = yoixPath(argv[0]);
int last = lastIndexOf(fullpath, '/');
String jarpath = substring(fullpath, 0, last+1) + bcjarfile;

adjustSecurity(ADDPROVIDER,
    "org.bouncycastle.jce.provider.BouncyCastleProvider",
    jarpath);

Key k = {
    Dictionary specification = {
	int type = ASYMMETRIC_KEY;
	String transformation = "RSA";
	String provider = "BC";
    };
};

Cipher c1 = {
    String specification = "RSA";
    int opmode = ENCRYPT_MODE;
    String initializer = k.keystring(PUBLIC_KEY);
};

Cipher c2 = {
    String specification = "RSA";
    int opmode = DECRYPT_MODE;
    String initializer = k.keystring(PRIVATE_KEY);
};

c1.text = "Try encrypting this text.";

Array encrypted = c1.text;

c2.text = encrypted;

fprintf(stdout, "Encrypted text:\n%s\n\n", btoh(encrypted));
fprintf(stdout, "Decrypted text:\n%s\n\n", c2.text);
 
 See Also:   adjustSecurity, Certificate, Cipher, KeyStore, Random

 

Yoix is a registered trademark of AT&T Inc.