Giovanni's logo
Encrypt & Decrypt
this means Version 2
index
M
power search
blue line

CGIDEV2 provides tools for encrypting and decrypting character strings and IFS stream files.

  1. Character strings
    1. Procedures
      • Encrypt() - Encrypt a character string
      • Decrypt() - Decrypt a character string
  2. Stream files
    1. Procedures
      • EncryptStmf() - Encrypt a stream file
      • DecryptStmf() - Decrypt a stream file
    2. 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.

  1. Encrypt() procedure
    Use this procedure to encrypt a character string.
    Parameters:
    1. 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.
    2. encryption key, character string, up to 16,000 chars
    3. 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);

  2. Decrypt() procedure
    Use this procedure to decrypt a character string previously crypted with procedure Crypt().
    Parameters:
    1. 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.
    2. encryption key, character string, up to 16,000 chars
    3. 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.

  3. EncryptStmf() procedure
    Use this procedure to encrypt a stream file.
    Parameters:
    1. encryption key, character string, up to 16,000 chars
    2. input stream file path (the one to be encrypted)
    3. 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);

  4. DecryptStmf() procedure
    Use this procedure to decrypt a stream file previously crypted with procedure CryptStmf().
    Parameters:
    1. decryption key, character string, up to 16,000 chars
    2. input stream file path (the one to be decrypted)
    3. 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.

  5. 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.

  6. 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.