CGIDEV2 provides tools for encrypting and decrypting character strings and IFS stream files.
- Character strings
- Procedures
- Encrypt() - Encrypt a character string
- Decrypt() - Decrypt a character string
- Stream files
- Procedures
- EncryptStmf() - Encrypt a stream file
- DecryptStmf() - Decrypt a stream file
- Commands
- ENCRYPTF - Encrypt a stream file
- DECRYPTF - Decrypt a stream file
|
Note 1 - All these tools need an "encryption key" character string be specified. To decrypt an item, the "key" used to encrypt it must be specified.
Note 2 - The encrypted string is twice as long the original string. This is because the encrypted data are represented in hexadecimal characters (2 hex chars per byte).
This hexadecimal data representation is quite independent from the its CCSID.
Note 3 - The job performing the decryption must run with the same CCSID as the job which performed the encrypt. When these jobs run with CCSID 65535, their default CCSID is used.
-
Encrypt() procedure
Use this procedure to encrypt a character string. Parameters:
- first call indicator - It must be mandatorily set to *ON in the first procedure call, thus enabling the "encryption key" to be stored for further calls.
The procedure sets it to *OFF at the end of the first call. It must stay *OFF in all further procedure calls.
- encryption key, character string, up to 16,000 chars
- input string to be encrypted, max 16,000 chars
The output encrypted string is twice as long.
* "Encrypt" procedure prototype
D Encrypt pr 32000 varying
D FirstCallInd n
D EncryptKey 16000 varying const options(*varsize)
D StringIn 16000 varying options(*varsize)
* EXAMPLE:
*D FirstCallInd s n
*D EncryptKey s 16000 varying
*D StringIn s 16000 varying
*D StringOut s 32000 varying
* /free
* FirstCallInd=*on;
* EncryptKey='GuessIt';
* StringIn='OpenSesami';
* StringOut=Encrypt(FirstCallInd:EncryptKey:StringIn); |
-
Decrypt() procedure
Use this procedure to decrypt a character string previously crypted with procedure Crypt(). Parameters:
- first call indicator - It must be mandatorily set to *ON in the first procedure call, thus enabling the "encryption key" to be stored for further calls.
The procedure sets it to *OFF at the end of the first call. It must stay *OFF in all further procedure calls.
- encryption key, character string, up to 16,000 chars
- input string to be decrypted, max 32,000 chars
The output decrypted string is half as long.
* "Decrypt" procedure prototype
D Decrypt pr 16000 varying
D FirstCallInd n
D DecryptKey 16000 varying const options(*varsize)
D StringIn 32000 varying options(*varsize)
* EXAMPLE:
*D FirstCallInd s n
*D DecryptKey s 16000 varying
*D StringIn s 32000 varying
*D StringOut s 16000 varying
* /free
* FirstCallInd=*on;
* DecryptKey='GuessIt';
* StringOut=Decrypt(FirstCallInd:DecryptKey:StringIn); |
See this sample program.
-
EncryptStmf() procedure
Use this procedure to encrypt a stream file. Parameters:
- encryption key, character string, up to 16,000 chars
- input stream file path (the one to be encrypted)
- output stream file path (the encrypted version of the input stream file).
This stream file does not have to already exist. If already existing, it is deleted, then re-created.
It is assigned the same CCSID of the input stream file.
Its data size will be twice the data size of the input stream file.
* "EncryptStmf" procedure prototype
D EncryptStmf pr 10i 0
D EncryptKey 16000 varying const options(*varsize)
D StmfIn 512
D StmfOut 512
* EXAMPLE:
* D rc s 10i 0
* D EncryptKey s 16000 varying
* D StmfIn s 512
* D StmfOut s 512
* /free
* EncryptKey='NeverGuess';
* StmfIn='/cgidev/html/sonnet29.txt';
* StmfOut='/tmp/sonnet29crypted.txt';
* rc=EncryptStmf(EncryptKey:StmfIn:StmfOut); |
-
DecryptStmf() procedure
Use this procedure to decrypt a stream file previously crypted with procedure CryptStmf(). Parameters:
- decryption key, character string, up to 16,000 chars
- input stream file path (the one to be decrypted)
- output stream file path (the decrypted version of the input stream file).
This stream file does not have to already exist. If already existing, it is deleted, then re-created.
It is assigned the same CCSID of the input stream file.
Its data size will be half the data size of the input stream file.
* "DecryptStmf" procedure prototype
D DecryptStmf pi 10i 0
D DecryptKey 16000 varying const options(*varsize)
D StmfIn 512
D StmfOut 512
* EXAMPLE:* D rc s 10i 0
* D DecryptKey s 16000 varying
* D StmfIn s 512
* D StmfOut s 512
* /free
* DecryptKey='NeverGuess';
* StmfIn='/tmp/sonnet29crypted.txt';
* StmfOut='/tmp/sonnet29decrypted.txt';
* rc=DecryptStmf(DecryptKey:StmfIn:StmfOut); |
See this sample program.
-
ENCRYPTF (Encrypt stream file) command
Use this command to encrypt a stream file.
This command calls procedure EncryptStmf() to perform its job.
Encrypt a stream file (ENCRYPTF)
Type choices, press Enter.
Stream file to be encrypted . . STMF
Encrypted stream file . . . . . TOSTMF
Key type . . . . . . . . . . . . KEYTYPE *CHAR *CHAR, *HEX
Encryption key . . . . . . . . . KEY
Encryption key . . . . . . . . . HEXKEY
Display TOSTMF . . . . . . . . . DSP *NO *YES, *NO |
- Stream file to be encrypted (STMF) - Path and name of the stream file to be crypted.
- Encrypted stream file (TOSTMF) - Path and name of the encrypted stream file that is to be created.
If this stream file alreaxdy exists, it is deleted and re-created.
This stream file is assigned the same CCSID of the original stream file.
- Key type (KEYTYPE) - Encryption key type. Select one of the following:
- *CHAR - The encryption key may contain any keyboard character.
- *HEX - The encryption key must contain a pair number of hexadecimal characters (0 to 9, A to F).
- Encryption key (KEY) - This parameter is used only when KEYTYPE(*CHAR).
Enter character string of up to 50 characters. Example: 'Open sesami'.
This string is used to perform the encryption of the stream file.
This "encryption key" must be retained as it is needed to decrypt the stream file.
- Encryption key (HEXKEY) - This parameter is used only when KEYTYPE(*HEX).
Enter a string of up to 100 hexadecimal characters (0 to 9, A to F). Example: 'adf507b283c4'.
This string is used to perform the encryption of the stream file.
This "encryption key" must be retained as it is needed to decrypt the stream file.
- Display TOSTMF (DSP) - Whether the encrypted stream file should be displayed.
-
DECRYPTF (Decrypt stream file) command
Use this command to decrypt a stream file previously created with procedure Cryptstmf() or with command CRYPTF.
This command calls procedure DecryptStmf() to perform its job.
Decrypt a stream file (DECRYPTF)
Type choices, press Enter.
Stream file to be decrypted . . STMF
Decrypted stream file . . . . . TOSTMF
Key type . . . . . . . . . . . . KEYTYPE *CHAR *CHAR, *HEX
Decryption key . . . . . . . . . KEY
Decryption key . . . . . . . . . HEXKEY
Display TOSTMF . . . . . . . . . DSP *NO *YES, *NO |
- Stream file to be decrypted (STMF) - Path and name of the stream file to be decrypted.
- Decrypted stream file (TOSTMF) - Path and name of the decrypted stream file that is to be created.
If this stream file alreaxdy exists, it is deleted and re-created.
This stream file is assigned the same CCSID of the encrypted stream file.
- Key type (KEYTYPE) - Encryption key type. Select one of the following:
- *CHAR - The encryption key may contain any keyboard character.
- *HEX - The encryption key must contain a pair number of hexadecimal characters (0 to 9, A to F).
Y
- Decryption key (KEY) - This parameter is used only when KEYTYPE(*CHAR).
Enter a character string of up to 50 characters. Example: 'Open sesami'.
This string is used to perform the decryption of the stream file and must be the same used to encrypt it.
- Decryption key (HEXKEY) - This parameter is used only when KEYTYPE(*CHAR).
Enter a string of up to 100 hexadecimal characters (0 to 9, A to F). Example: 'adf507b283c4'.
This string is used to perform the decryption of the stream file and must be the same used to encrypt it.
- Display TOSTMF (DSP) - Whether the decrypted stream file should be displayed.
|