If something seems wrong or incomplete, please enter a comment at the bottom of this page.
- source - main - QA - jscrypt modulejscrypt is a cryptographic toolkit that provides developers with a vast array of well known published block ciphers,
one-way hash functions, chaining modes, pseudo-random number generators, public key cryptography and a plethora of other routines.
The underlying native code of this module is based on LibTom library.
jscrypt static members- top - revision - Static functionsBase64Encodestring Base64Encode( string )
Encode the given string using base64 encoding.
Base64Decodestring Base64Decode( string )
Encode the given string using base64 encoding.
HexEncodestring HexEncode( string )
Encode the given string using hexadecimal encoding.
HexDecodestring HexDecode( string )
Decode the given string using hexadecimal encoding.
class jscrypt::Cipher- top - revision - constructorconstructor( modeName, cipherName, key, [IV], [arg], [rounds] )
Constructs a Cipher object that use cipherName algorithm for performing encryption and decryption.
arguments:
- string modeName: is the block cipher modes of operation:
- ECB (Electronic codebook)
- CFB (Cipher feedback)
- OFB (Output Feedback)
- CBC (Cipher Block Chaining)
- CTR (CounTeR)
- LRW
- F8
- string cipherName: is the name of the cipher algorithm used for data encryption and decryption:
- blowfish
- rc5
- rc6
- rc2
- saferp
- safer_k64, safer_k128, safer_sk64, safer_sk128
- rijndael, aes
- rijndael_enc, aes_enc
- xtea
- twofish
- des, des3
- cast5
- noekeon
- skipjack
- khazad
- anubis
- kseed
- kasumi
- string key: is the encryption/decryption key.
- string IV:
IV is the first initialization vector:
The IV value is the initialization vector to be used with the cipher.
You must fill the IV yourself and it is assumed they are the same length as the block size of the cipher you choose.
It is important that the IV be random for each unique message you want to encrypt.
beware:
This argument is invalid in ECB block mode.
- string arg: is either the tweak key for the LRW mode or the salt value for the F8 mode. In other modes arg must be undefined.
beware:
In LRW mode, the tweak value must have the same length as the key.
- integer rounds: is the number of rounds to do with the current sipher. If the argument is omitted, a default value is used.
MethodsEncryptbstring Encrypt( data )
Encrypts the given data using the current cipher.
Decryptbstring Decrypt( data )
Decrypts the given data using the current cipher.
PropertiesblockLengthinteger blockLength
Is the block length of the current cipher.
keySizeinteger keySize
Is the key size of the current cipher.
namestring name
Is the name of the current cipher.
IVstring IV
Set or get the current initialization vector of the cipher.
Static propertieslistObject list
Contains the list of all available ciphers and their feature. The list is a javascript object that map cipher names (key) with another object (value) that contain information.
class jscrypt::AsymmetricCipher- top - revision - constructorconstructor( cipherName, hashName [, prngObject] [, PKCSVersion = 1_OAEP] )
Creates a new Asymmetric Cipher object.
arguments:
- string cipherName: is a string that contains the name of the Asymmetric Cipher algorithm:
- string hashName: is the hash that will be used to create the PSS (Probabilistic Signature Scheme) encoding. It should be the same as the hash used to hash the message being signed. See Hash class for available names.
- Object prngObject: is an instantiated Prng object. Its current state will be used for key creation, data encryption/decryption, data signature/signature check. This argument can be ommited if you aim to decrypt data only.
- string PKCSVersion: is a string that contains the padding version used by RSA to encrypt/decrypd data:
- 1_OAEP (for PKCS #1 v2.1 encryption)
- 1_V1_5 (for PKCS #1 v1.5 encryption)
If omitted, the default value is 1_OAEP.
Only RSA use this argument.
MethodsCreateKeysCreateKeys( keySize )
Create RSA public and private keys.
keySize is the size of the key in bits (the value of keySize is the modulus size).
note:
supported RSA keySize: from 1024 to 4096 bits
supported ECC keySize: 112, 128, 160, 192, 224, 256, 384, 521, 528 bits
supported DSA keySize (Bits of Security): ???, 80, 120, 140, 160, ??? bits
Encryptbstring Encrypt( data [, lparam] )
This function returns the encrypted data using a previously created or imported public key.
data is the string to encrypt (usualy cipher keys).
Decryptbstring Decrypt( encryptedData [, lparam] )
This function decrypts the given encryptedData using a previously created or imported private key.
encryptedData is the string that has to be decrypted (usualy cipher keys).
note:
The lparam variable is an additional system specific tag that can be applied to the encoding.
This is useful to identify which system encoded the message.
If no variance is desired then lparam can be ignored or set to undefined.
If it does not match what was used during encoding this function will not decode the packet.
When performing v1.5 RSA decryption, the hash and lparam parameters are totally ignored.
Signstring Sign( data [, saltLength] )
This function returns the signature of the given data.
Because this process is slow, this function usualy used to sign a small amount of data, like hash digest.
saltLength is only used with RSA signatures. (default value is 16)
VerifySignatureboolean VerifySignature( data, signature [, saltLength] )
This function returns true if the data match the data used to create the signature.
saltLength is only used with RSA signatures. (default value is 16)
PropertiesblockLengthinteger blockLength
is the maximum length of data that can be processed at once.
keySizeinteger keySize
is the size of the current key.
keystring privateKey
The private key encoded using PKCS #1. (Public Key Cryptographic Standard #1 v2.0 padding)
- string publicKey
The public key encoded using PKCS #1. (Public Key Cryptographic Standard #1 v2.0 padding)
ExampleData (or key) encryption using RSA: LoadModule('jsstd');
LoadModule('jscrypt');
var fortuna = new Prng('fortuna');
fortuna.AutoEntropy(123); // give more entropy
//Alice
var alice = new AsymmetricCipher('RSA', 'md5', fortuna);
alice.CreateKeys(1024);
var publicKey = alice.publicKey;
//Bob
var bob = new AsymmetricCipher('RSA', 'md5', fortuna);
bob.publicKey = publicKey;
var encryptedData = bob.Encrypt('Alice, I love you !');
//Alice
Print( alice.Decrypt(encryptedData), '\n' );
class jscrypt::Hash- top - revision - This class is used to create block Hash objects.
constructorconstructor( hashName )
Creates a new hash.
hashName is a string that contains the name of the hash:
- whirlpool
- sha512
- sha384
- sha256
- sha224
- sha1
- md5
- md4
- md2
- tiger
- rmd128
- rmd160
- rmd256
- rmd320
- chc_hash
note:
chc_hash is a special hash that allows to create a hash from a cipher (Cipher Hash Construction).
See CipherHash() static function.
MethodsInitInit()
Initialize the hash state.
Processvoid Process( data )
Process a block of data though the hash.
Donebstring Done()
Terminate the hash and get the digest in a binary format.
example:
LoadModule('jsstd');
LoadModule('jscrypt');
var md5 = new Hash('md5');
md5.Process('foo');
md5.Process('bar');
Print( HexEncode( md5.Done(), '\n' ) ); // prints: 3858F62230AC3C915F300C664312C63F call operatorbstring call operator( data )
This is the call operator of the object. It simplifies the usage of hashes and allows a digest calculation in one call only.
When called with a string as argument, it Process a block of memory though the hash
Compute the hash until the function is called without arguments or end is true. In this case, the function returns the hash of the whole given data.
beware:
Using this methode to compute a digest automaticaly resets previous state let by Init(), Process() or Done().
example:
LoadModule('jsstd');
LoadModule('jscrypt');
var md5 = new Hash('md5');
Print( HexEncode( md5('foobar') ) ); // prints: 3858F62230AC3C915F300C664312C63F Propertiesnamestring name
Name of the current hash.
blockSizeinteger blockSize
Input block size in octets.
lengthinteger length
Size of the digest in octets.
inputLengthinteger inputLength
Length of the processed data.
Static functionsCipherHashCipherHash( cipherName )
Initialize the CHC (chc_hash) state with cipherName cipher.
An addition to the suite of hash functions is the Cipher Hash Construction or CHC mode.
In this mode applicable block ciphers (such as AES) can be turned into hash functions that other functions can use.
In particular this allows a cryptosystem to be designed using very few moving parts.
Static propertieslistObject list
Contains the list of all available hash and their feature. The list is a javascript object that map hash names (key) with another object (value) that contain information.
example:
LoadModule('jsstd');
LoadModule('jscrypt');
Print('hash list: ' + Hash.list.toSource() );
class jscrypt::Prng- top - revision - This class is used to create pseudo random number generators objects.
constructorconstructor( prngName )
Constructs a pseudo random number generator object using the given algorithm.
arguments:
- string prngName: is a string that contains the name of the Asymmetric Cipher algorithm:
- yarrow
- fortuna
- rc4
- sprng
- sober128
Methodscall operatorstring call operator( size )
Returns size bytes of pseudo-random data.
example:
LoadModule('jsstd');
LoadModule('jscrypt');
var myGen = new Prng('yarrow');
myGen.AutoEntropy(128); // give more entropy
Print(HexEncode(myGen(100))); // prints random data AddEntropyvoid AddEntropy( data )
Add data as entropy (randomness) to the current prng.
AutoEntropyvoid AutoEntropy( size )
Automaticaly add size bits of entropy to the current prng.
Static propertiesstatebstring state
is the current state of the prng.
namestring name
is the name of the current prng.
listObject list
Contains the list of all available prng and their feature. The list is a javascript object that map cipher names (key) with another object (value) that contain information.
class jscrypt::CryptError- top -
- top - main -
|