Using Encrpt Data API

pts.
Tags:
RPG
Has anyone been successful in using the encrypt data API QC3ENCDT (OPM) in RPG IV? When using algorithm description format name ALGD0200, I get error message CPF9DEE, Reserved field not null. "Reserved" is a one character field; and the sixth parameter on the format data structure. Documentation says "Reserved" must be set to null (binary 0s).Does anyone know how to set this field to 'NULL'?

Answer Wiki

Thanks. We'll let you know when a new response is added.

That’s funny…i was just coding it yesterday when i got the same error message…i followed everything in the manual…but i still see the same msg.

If i can make it work by tomorrow, will send you a code-snippet…

==============================================================

Since no new info has been added, here’s a trivial example of encrypting with Triple-DES and decrypting back again into a different output variable for comparison.
<pre>
pgm

dcl &ClearText *char 32 value( ‘Let”s get encrypted, hmm?’ )
dcl &ClearTextO *char 32 value( ‘ ‘ )
dcl &lClearText *int 4 value( 32 )
dcl &lClearTxtR *int 4 value( 0 )
dcl &AlgDesc *char 52
dcl &KeyDesc *char 36
dcl &CryptSrv *char 1 value( ’0′ ) /* Any */
dcl &CryptDev *char 10 value( ‘ ‘ ) /* None */
dcl &EncData *char 128
dcl &lEncDataA *int 4 value( 128 )
dcl &lEncDataR *int 4 value( 0 )
dcl &ErrCod *char 4 value( x’00000000′ )

dcl &fALGD0200 *char 52
dcl &BlkCAlg *char 4
dcl &lBlk *char 4
dcl &Mode *char 1 value( ’1′ ) /* CBC */
dcl &PadOpt *char 1 value( ’1′ ) /* use pad char */
dcl &PadChar *char 1 value( x’00′ )
dcl &rsvAlg1 *char 1 value( x’00′ )
dcl &lMAC *char 4 value( x’00000000′ ) /* null */
dcl &szEffKey *char 4 value( x’00000000′ ) /* null for T-DES */
dcl &InitVector *char 32 value( x’0123456789ABCDEF’ ) /* random */

dcl &fKEYD0200 *char 36
dcl &KeyType *char 4 value( x’00000015′ ) /* 21 T-DES */
dcl &lKeyStr *char 4 value( x’00000018′ ) /* 24 */
dcl &fKey *char 1 value( ’0′ ) /* binary string */
dcl &rsvKey1 *char 3 value( x’000000′ )
dcl &KeyStr *char 24 value( ‘My own encrypt key|?????’ )

/* Explicitly set T-DES algorithm and block-size… */

chgvar %bin( &BlkCAlg ) ( 21 ) /* Triple-Des */
chgvar %bin( &lBlk ) ( 8 ) /* Triple-Des */

/* Assemble algorithm description (0200 format)… */

chgvar &fALGD0200 ( +
&BlkCAlg *cat +
&lBlk *cat +
&Mode *cat +
&PadOpt *cat +
&PadChar *cat +
&rsvAlg1 *cat +
&lMAC *cat +
&szEffKey *cat +
&InitVector +
)

/* Assemble key description (0200 format)… */

chgvar &fKEYD0200 ( +
&KeyType *cat +
&lKeyStr *cat +
&fKey *cat +
&rsvKey1 *cat +
&KeyStr +
)

/* Encrypt our clear text into &EncData… */

callprc ‘Qc3EncryptData’ ( +
&ClearText +
&lClearText +
‘DATA0100′ +
&fALGD0200 +
‘ALGD0200′ +
&fKEYD0200 +
‘KEYD0200′ +
&CryptSrv +
&CryptDev +
&EncData +
&lEncDataA +
&lEncDataR +
&ErrCod +
)

/* Decrypt our encrypted data into &ClearTextO… */

callprc ‘Qc3DecryptData’ ( +
&EncData +
&lEncDataR +
&AlgDesc +
‘ALGD0200′ +
&KeyDesc +
‘KEYD0200′ +
&CryptSrv +
&CryptDev +
&ClearTextO +
&lClearText +
&lClearTxtR +
&ErrCod +
)

dmpclpgm

return

endpgm
</pre>
Note that &rsvAlg1 and &rsvKey1 are simply hex zeroes (binary zeroes as a result).

Tom

Discuss This Question: 5  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Wimcamp
    Eval Reserved = x'00'
    0 pointsBadges:
    report
  • Syedmohsin4
    Hi I have been working on Encryption/Decryption of data on AS400 v5R4. I have already done the Encryption of data using QC3ENCDT API on COBOOL. Now, I want to use the RSA Public key to encrypt my encryption key. For that I had written a test program but it is throwing one error and I m unable to find the cause of the error: The error code is CPF9DDB. Description is The key string or Diffie-Hellman parameter string is not valid Cause is Either there is an error in the BER encoding or the BER encoded string describes an object not valid for this operation. Here is my code in cobol:
    
     01 WS-PUBLIC-KEY     PIC X(512).                                 
     01 WS-PRIVATE-KEY    PIC X(512).                                 
     01 WS-CIPHER-DATA-1  PIC X(1024).                                
     01 WS-KEYD.                                                      
        05 WS-KEY-TYPE-2         PIC 9(8) USAGE BINARY VALUE 50.      
        05 WS-KEY-LENGTH         PIC 9(8) USAGE BINARY VALUE 92.      
        05 WS-KEY-FORMAT-2       PIC X(1) VALUE '1'.                  
    *   05 WS-RESERVED           PIC X(3).                            
        05 WS-KEY-STRING         PIC X(512).                          
                                                                      
         EXEC SQL END DECLARE SECTION END-EXEC.                       
                                                                      
                                                                      
     01 KEY-TYPE-1                PIC 9(8) USAGE BINARY VALUE 50.     
     01 KEY-SIZE                  PIC 9(8) USAGE BINARY VALUE 512.    
     01 PKE                       PIC 9(8) USAGE BINARY VALUE 65537.  
     01 KEY-FORMAT-1              PIC X(1) VALUE '1'.                 
     01 KEY-FORM                  PIC X(1) VALUE '0'.                 
     01 KEK-CTXT-TOKN             PIC X(8).                           
     01 KEK-ALG-CTXT-TOKN         PIC X(8).                           
     01 CRYPTO-SP-1               PIC X(1) VALUE '1'.                 
                                                                      
    01 CRPTO-DEVICE-1            PIC X(10) VALUE SPACES.            
    01 PVT-KEY-STRING            PIC X(512).                        
    01 LOA-PVT-KS                PIC 9(8) USAGE BINARY VALUE 512.   
    01 LENGTH-PVT-KS             PIC 9(8) USAGE BINARY.             
    01 PUB-KEY-STRING            PIC X(512).                        
    01 LOA-PUB-KS                PIC 9(8) USAGE BINARY VALUE 512.   
    01 LENGTH-PUB-KS             PIC 9(8) USAGE BINARY.             
    01 ERR1.                                                        
       05 BYTES-PRVD             PIC 9(8) USAGE BINARY VALUE 64.    
       05 BYTES-AVAIL            PIC 9(8) USAGE BINARY.             
       05 EXC-ID                 PIC X(7).                          
       05 RESERVED               PIC X(1) VALUE B'0'.               
       05 EXC-DATA               PIC X(20).                         
                                                                    
     Variables for Encryption API                                   
                                                                    
    01 WS-CLEAR-DATA     PIC X(64) VALUE 'MOHSIN'.                  
    01 LENGTH-CD         PIC 9(8) USAGE BINARY VALUE 64.            
    01 CD-FMT            PIC X(8) VALUE 'DATA0100'.                 
    01 ALGO.                                                        
       05 PKC-ALGO           PIC 9(8) USAGE BINARY VALUE 50.        
                                                                    
        05 PKA-BLOCK-FMT      PIC X(1) VALUE '2'.                   
    *   05 RESERVED           PIC X(1) VALUE B'0'.                  
    *   05 SCA                PIC 9(8) USAGE BINARY.                
                                                                    
     01 ALGO-FMT-NAME         PIC X(8) VALUE 'ALGD0400'.            
                                                                    
     01 KEYD.                                                       
        05 KEY-TYPE-2         PIC 9(8) USAGE BINARY VALUE 50.       
        05 KEY-LENGTH         PIC 9(8) USAGE BINARY VALUE 92.       
        05 KEY-FORMAT-2       PIC X(1) VALUE '1'.                   
    *   05 RESERVED           PIC X(3).                             
        05 KEY-STRING         PIC X(512).                           
     01 KEYD-FMT-NAME         PIC X(8) VALUE 'KEYD0200'.            
                                                                    
     01 CRYPTO-SP-2           PIC X(1) VALUE '1'.                   
     01 CRPTO-DEVICE-2        PIC X(10) VALUE SPACES.               
     01 WS-CIPHER-DATA        PIC X(1024).                          
     01 LOA-CIPHER-DATA       PIC 9(8) USAGE BINARY VALUE 1024.     
     01 LENGTH-CIPHER-DATA    PIC 9(8) USAGE BINARY.                
     01 ERR2.                                                       
        05 BYTES-PRVD         PIC 9(8) USAGE BINARY VALUE 64.       
        05 BYTES-AVAIL        PIC 9(8) USAGE BINARY.              
        05 EXC-ID             PIC X(7).                           
    *   05 RESERVED           PIC X(1) VALUE B'0'.                
        05 EXC-DATA           PIC X(20).                          
    /                                                             
     LINKAGE SECTION.                                             
                                                                  
    **************************************************************
     PROCEDURE DIVISION.                                          
    **************************************************************
                                                                  
     0000-MAIN.                                                   
                                                                  
         PERFORM   1000-INIT-PARA                                 
            THRU   1000-EXIT.                                     
                                                                  
         PERFORM   2000-PROCESS-PARA                              
            THRU   2000-EXIT.                                     
                                                                  
         PERFORM   9000-OVER-PARA                                 
            THRU   9000-EXIT.                                     
                                                                 
     0000-EXIT.                                                  
          EXIT.                                                  
    /                                                            
    *************************************************************
    * Housekeeping Routine                                       
    *************************************************************
                                                                 
     1000-INIT-PARA.                                             
                                                                 
         MOVE SPACES TO CRPTO-DEVICE-1                           
                        CRPTO-DEVICE-2                           
                        WS-CLEAR-DATA.                           
         INITIALIZE PVT-KEY-STRING                               
                    PUB-KEY-STRING.                              
                                                                 
    *  Set up error handling work area.                          
         INITIALIZE WS04-ERROR-DETAIL-AREA.                      
                                                                 
         SET   NO-ERRORS                TO TRUE.                 
         MOVE 'BASSYS0018'              TO WS04-HOLD-PROG-NAME.  
                                                                 
         MOVE 'POL'                     TO WS04-HOLD-KEY-TYPE.    
         STRING  ' '                    DELIMITED BY SIZE         
                 ';'                    DELIMITED BY SIZE         
           INTO WS04-HOLD-KEY-STRING                              
         END-STRING.                                              
                                                                  
     1000-EXIT.                                                   
          EXIT.                                                   
    /                                                             
                                                                  
                                                                  
    **************************************************************
    * Processing Paragraph                                        
    **************************************************************
                                                                  
     2000-PROCESS-PARA.                                           
                                                                  
                                                                  
         CALL 'QC3GENPK' USING KEY-TYPE-1                         
                               KEY-SIZE                           
                               PKE                                
                              KEY-FORMAT-1                    
                              KEY-FORM                        
                              KEK-CTXT-TOKN                   
                              KEK-ALG-CTXT-TOKN               
                              CRYPTO-SP-1                     
                              CRPTO-DEVICE-1                  
                              PVT-KEY-STRING                  
                              LOA-PVT-KS                      
                              LENGTH-PVT-KS                   
                              PUB-KEY-STRING                  
                              LOA-PUB-KS                      
                              LENGTH-PUB-KS                   
                              ERR1.                           
                                                              
        MOVE PUB-KEY-STRING       TO KEY-STRING.              
    
                                                             
         CALL 'QC3ENCDT' USING WS-CLEAR-DATA                 
                               LENGTH-CD                     
                               CD-FMT                        
                               ALGO                          
                               ALGO-FMT-NAME                 
                               KEYD                          
                               KEYD-FMT-NAME                 
                               CRYPTO-SP-2                   
                               CRPTO-DEVICE-2                
                               WS-CIPHER-DATA                
                               LOA-CIPHER-DATA               
                               LENGTH-CIPHER-DATA            
                               ERR2.                         
                                                             
     2000-EXIT.                                              
          EXIT.                                              
    /                                                        
    *********************************************************
    
    55 pointsBadges:
    report
  • TomLiotta
    @Syedmohsin4: Please open your question in a new item. Post the same code and description in that item, but also tell us which API throws the error. (Both QC3GENPK and QC3ENCDT can signal the CPF9DDB error message.) Thank you. Tom
    125,585 pointsBadges:
    report
  • Syedmohsin4
    Hi Tom, The error was thrown in the API QC3ENCDT. I have opened a new question for this. Here is the link: Thanks! -Mohsin
    report
  • Syedmohsin4
    Hi Tom, The error was thrown in the API QC3ENCDT. I have opened a new question for this. Here is the link. Using API QC3ENCDT in encryption using RSAalgorithm under a Public key, error CPF9DD Thanks! -Mohsin
    55 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following