IBM Crypto Education Community

IBM Crypto Education Community

IBM Crypto Education Community

Join the IBM Crypto Education community to explore and understand IBM cryptography technology. This community is operated and maintained by the IBM Crypto Development team.

 View Only

Rexx Sample: Decrypt with Secure Key

By Eysha Shirrine Powers posted Wed March 25, 2020 05:28 PM

  

/* Rexx */
 
/*-----------------------------------------------------------------*/
/* Description:                                                    */
/*                                                                 */
/* Decrypt data with the secret key                                */
/*                                                                 */
/*-----------------------------------------------------------------*/
sad_rule_array_count = '00000003'x;
sad_rule_array = 'AES     ' || 'PKCS-PAD' || 'KEYIDENT';
sad_key_identifier_length = '00000040'x;
sad_key_identifier = left('SAMPLE.SECRET.AES256.KEY001',64);
sad_init_vector_length = '00000010'x;
sad_init_vector = '11111111111111111111111111111111'x;
sad_block_size = '00000010'x;
sad_cipher_text_length = '00000010'x;
sad_cipher_text = '552862D1D71FA24A6AB916464887AF4F'x;
sad_clear_text_length = '00000040'x;
sad_clear_text = copies('00'x,64);
 
Call CSNBSAD;
 
clear_text = substr(sad_clear_text,1,c2d(sad_clear_text_length));
say 'Clear Text: ' clear_text;
 
Exit;
 
/* --------------------------------------------------------------- */
/* CSNBSAD - Symmetric Algorithm Decipher                          */
/*                                                                 */
/* Decrypts data using a secure, symmetric key                     */
/*                                                                 */
/* See the ICSF Application Programmer's Guide for more details.   */
/* --------------------------------------------------------------- */
CSNBSAD:
 
sad_rc = 'FFFFFFFF'x;
sad_rs = 'FFFFFFFF'x;
sad_exit_data_length = '00000000'x;
sad_exit_data = '';
sad_key_parms_length = '00000000'x;
sad_key_parms = '';
sad_chain_data_length = '00000020'x;
sad_chain_data =  copies('00'x,32);
sad_optional_data_length = '00000000'x;
sad_optional_data = '';
 
ADDRESS linkpgm "CSNBSAD",
   'sad_rc'                          'sad_rs'               ,
   'sad_exit_data_length'            'sad_exit_data'        ,
   'sad_rule_array_count'            'sad_rule_array'       ,
   'sad_key_identifier_length'       'sad_key_identifier'   ,
   'sad_key_parms_length'            'sad_key_parms'        ,
   'sad_block_size'                                         ,
   'sad_init_vector_length'          'sad_init_vector'      ,
   'sad_chain_data_length'           'sad_chain_data'       ,
   'sad_cipher_text_length'          'sad_cipher_text'      ,
   'sad_clear_text_length'           'sad_clear_text'       ,
   'sad_optional_data_length'        'sad_optional_data';
 
if (SAD_RC /= '00000000'x) Then
  say 'SAD Failed   (rc=' c2x(SAD_RC)' rs='c2x(SAD_rs)')' ;
 
return;
 

0 comments
16 views

Permalink