midrange.com code scratchpad
Name:
Qc3DecryptData
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
06/16/2010 05:21:10 pm
IP:
Logged
Description:
Qc3DecryptData gives me a different result from http://www.unsw.adfa.edu.au/~lpb/src/AEScalc/AEScalc.html
Code:
  1.      D reffldIBMErrorDS...
  2.      D                 DS                  qualified
  3.      D  totalLen                     10I 0 Inz(%Size(reffldIBMErrorDS))
  4.      D  resultLen                    10I 0 inz(0)
  5.      D  msgID                         7A
  6.      D  reserved                      1A   inz(x'00')
  7.      D  msgDta                      256A
  8.  
  9.      D ALGD0200InAES256ECBMode...
  10.      D                 DS                  qualified
  11.      D  algorithm                    10i 0 inz(@AESAlgorithm)
  12.      D  algorithmBlockLen...
  13.      D                               10i 0 inz(32)
  14.      D  mode                          1    inz(@ECBMode)
  15.      D  padOption                     1    inz('0')
  16.      D  padChar                       1    inz(x'00')
  17.      D  reserved                      1    inz(x'00')
  18.      D  MACLen                       10i 0 inz(0)
  19.      D  keySize                      10i 0 inz(0)
  20.      D  inzVector                    32    inz(*allx'00')
  21.  
  22.      D KEYD0200InAES256ECBMode...
  23.      D                 DS                  qualified
  24.      D  keyType                      10i 0 inz(@AESAlgorithm)
  25.      D  keyLen                       10i 0 inz(32)
  26.      D  keyFormat                     1    inz('0')
  27.      D  reserved                      3    inz(*allx'00')
  28.      D  key                          32
  29.  
  30.       *------------------------------------------------------------------
  31.       * const
  32.       *------------------------------------------------------------------
  33.      D @AESAlgorithm   C                   const(22)
  34.      D @ECBMode        C                   const('0')
  35.      D @SUCCESSFUL     C                   const('1')
  36.  
  37.  
  38.       *------------------------------------------------------------------
  39.       * variable
  40.       *------------------------------------------------------------------
  41.      D decryptedPwd    s            256
  42.  
  43.       *------------------------------------------------------------------
  44.       * copy book
  45.       *------------------------------------------------------------------
  46.  
  47.       *------------------------------------------------------------------
  48.       * prototype
  49.       *------------------------------------------------------------------
  50.      D setDecryptedPwd...
  51.      D                 pr              n
  52.  
  53.       * ibm decryt api
  54.      D Qc3DecryptData  PR                  ExtProc('Qc3DecryptData')
  55.      D  piEncData                 65535A   OPTIONS(*VARSIZE)
  56.      D                                     const
  57.      D  piEncDataLen                 10I 0 Const
  58.  
  59.      D  piAlgorithm                  64A   Const OPTIONS(*VARSIZE)
  60.      D  piAlgorithmFmt...
  61.      D                                8A   Const
  62.  
  63.      D  piKeyDesc                   512A   Const OPTIONS(*VARSIZE)
  64.      D  piKeyFormat                   8A   Const
  65.      D  piCryptoServiceProvider...
  66.      D                                1A   Const
  67.      D  piCryptoDeviceName...
  68.      D                               10A   Const options(*omit)
  69.      D  piClearData               65535A   OPTIONS(*VARSIZE)
  70.      D  piClearDataSizeProvider...
  71.      D                               10I 0 Const
  72.      D  piClearDataLen...
  73.      D                               10I 0
  74.      D  piApiErrorDS                       LikeDS(reffldIBMErrorDS)
  75.      D                                     OPTIONS(*VARSIZE)
  76.  
  77.       *------------------------------------------------------------------
  78.       * main
  79.       *------------------------------------------------------------------
  80.       *
  81.       /free
  82.  
  83.        setDecryptedPwd();
  84.  
  85.        *inlr = *on;
  86.  
  87.       /end-free
  88.  
  89.       *-------------------------------------------------------------------------
  90.       * Decrypt the password
  91.       *-------------------------------------------------------------------------
  92.      P setDecryptedPwd...
  93.      P                 B
  94.      D                 pi              n
  95.  
  96.  
  97.      D myEncryptedData...
  98.      D                 s          65535A
  99.      D myClearData     s          65535A
  100.      D myClearDataLen...
  101.      D                 s             10I 0
  102.      D myIBMApiErr     ds                   likeDS(reffldIBMErrorDS)
  103.  
  104.       /free
  105.  
  106.        myIBMApiErr = reffldIBMErrorDS;
  107.        KEYD0200InAES256ECBMode.key =
  108.          x'8181818181818181818181818181818181818181818181818181818181818181';
  109.        myEncryptedData =
  110.          x'59a10915306238b011ba322354c608e6';
  111.        Qc3DecryptData(myEncryptedData         :32
  112.                      :ALGD0200InAES256ECBMode :'ALGD0200'
  113.                      :KEYD0200InAES256ECBMode :'KEYD0200'
  114.                      :'0'                     :' '
  115.                      :myClearData             :%size(myClearData)
  116.                      :myClearDataLen          :myIBMApiErr
  117.                      );
  118.          if myIBMApiErr.resultLen <> 0;
  119.            return not @SUCCESSFUL;
  120.          else;
  121.            decryptedPwd = %subst(myClearData :1 :myClearDataLen);
  122.            return @SUCCESSFUL;
  123.          endif;
  124.  
  125.       /end-free
  126.  
  127.      P setDecryptedPwd...
  128.      P                 E
© 2004-2019 by midrange.com generated in 0.006s valid xhtml & css