sponsored links

Collapse

Announcement

Collapse
No announcement yet.

Decryption ??

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Decryption ??

    Once I do this

    Code:
    insert into  oezoord(ozcname) values       
    ENCRYPT('289-46-8832','firehawk','Canada')

    How do I get it decrypted.

    I have tryed both DECRYPT and DECRYPT_CHAR
    but cant seem to get it right.

    Code:
    d somefield       s             60             
     *                                             
    c/exec sql                                     
    c+ select   DECRYPT_CHAR(ozcname,'firehawk')   
    c+    into :somefield                          
    c+    from oezoord                             
    c+    where oztype = 'X'                       
    c/end-exec                                     
     *                                             
    c                   eval      *inlr = *on

    Thanks in advance

    Jamie
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

  • #2
    Re: Decryption ??

    Jamie,

    Pls go thro http://www.itjungle.com/fhg/fhg063004-story01.html

    I think this will explain the stuff u want.
    Code:
     ENCRYPTION FUNCTIONS
    
    Every now and then a programmer gets the job of storing sensitive data. 
    This data is to be protected from peering eyes by disallowing any one 
    (even with *ALLOBJ authority) from making sense of the data. This job 
    of storing data in an encrypted format is now easy, as V5R3 introduces 
    functions to encrypt and decrypt string data. The Cryptographic Access 
    Provider 128-bit for AS/400 product (5722AC3) must be installed in 
    order for these functions to work.
    
    Here's how the functions operate:
    
    Encrypt_RC2 accepts string data to encrypt, an optional password, 
    and an optional password hint. The function returns an encrypted 
    string result using the RC2 encryption algorithm. The original 
    password string must be preserved (by user's memory, database 
    file, etc.) in order to decrypt the data. The optional hint 
    string can be used to assist a user in remembering the password.
    
    
    	
    	
    	
    
    
    Code:
    Insert Into TreasureMaps 
    (TreasureID, TreasureValue, Directions)
    Values(1,50000.00,
    /* Insert directions to treasure in encrypted format */
    Encrypt_RC2('30 paces to the palm tree -- Turn Left','Caribbean','Pirates'))
    Note that the data, the password, and the hint are stored in the encrypted result. The password can be between 6 and 127 bytes, and the hint can be up to 32 bytes. The IBM SQL reference manual (in PDF format) contains guidelines on how to calculate the number of bytes required to store all three pieces of information. Decrypt--Once data has been encrypted, one of several decryption functions is available: Decrypt_Bit, Decrypt_Binary, Decrypt_Char, and Decrypt_DB. Each decryption function is available for decrypting data into the original format (binary, character, etc.). These functions accept an RC2-encrypted string and an optional password string. The Decrypt_Char and Decrypt_DB functions accept an optional third parameter for specifying a CCSID for the resulting string.
    Code:
    Select Decrypt_Char(Directions,'Caribbean')
    /* Result will be:
       '30 paces to the palm tree -- Turn Left' */
      From TreasureMaps
     Where TreasureID=1
    If an invalid password is supplied, the statement fails with an error. If a common password was used to encrypt data, the password can be set for a session as follows:
    Code:
    Set Encryption Password = 'Caribbean'
    When the optional password is absent, the decrypt functions heed the password set by the SET ENCRYPTION PASSWORD statement:
    Code:
    Select Decrypt_Char(Directions)
    /* The password isn't needed here */
      From TreasureMaps
     Where TreasureID=1
    The SET ENCRYPTION PASSWORD also applies to encrypting data if the optional password is not specified when using the Encrypt_RC2 function. GetHint is used to retrieve the password hint from a string encrypted with a hint. The only parameter is an encrypted string.
    Code:
    Select GetHint(Directions)
           /* Based on the above example, 
              GetHint will return 'Pirates' */
      From TreasureMaps
     Where TreasureID=1
    The GetHint function is particularly valuable for applications that allow users to store their own passwords in an encrypted format. The encryption functions are useful for storing sensitive data such as passwords or credit card numbers. Don't forget, for client/server applications, these encryption routines will not protect your data by passing encrypted strings across the network. SSL and the like should be used for network protection. Also, don't forget that there is a performance penalty for encrypting and decrypting data, so don't overuse it!
    Thanks,
    Giri

    Comment


    • #3
      Re: Decryption ??

      Okay heres what I have now

      a physical file call @SECURITY with one field called secret

      Code:
                                 Display File Fields                                
                                                Position to . . . . . .:            
       Physical File  . . . . .: @SECURITY      File Type . . . . . . .:         PF 
       Library  . . . . . . . .: JAMIELIB       Record Length . . . . .:         30 
       Record Format. . . . . .: SECR           Number of fields. . . .:          1 
                                                                                    
       Key Field     Length Dec Type From    To Text                                
           SECRET        30      A      1    30
      i run this

      Code:
      insert into  @security(secret) values             
      ENCRYPT_RC2('Cant make work','firehawk','Canada')
      it works I get this in file (or something like that )

      Code:
        Record#  SECRET                            
              1  3ŸŸNvCanadat|ÿ1*}ZB¹N^LF
      then I run this

      Code:
      SELECT Decrypt_char(secret) FROM @security
      and get this error
      Argument 01 of function DECRYPT_CHAR not valid.

      also I have these installed

      Code:
      5722AC3   *INSTALLED   Crypto Access Provider 128-bit  
      5722CE3   *INSTALLED   Client Encryption 128-bit
      So where am I going wrong?

      Thanks
      Jamie
      All my answers were extracted from the "Big Dummy's Guide to the As400"
      and I take no responsibility for any of them.

      www.code400.com

      Comment


      • #4
        Re: Decryption ??

        I tried what you did and got the same error. I called IBM Software support and was told that you have to use CHAR FOR BIT DATA, VARCHAR FOR BIT DATA, BINARY, VARBINARY or BLOB fields rather than a simple CHAR field. Recreate your file with

        CREATE TABLE oezoord (ozcname CHAR(xx) FOR BIT DATA)

        and you should be good to go.

        Pete
        Last edited by Pete; January 6th, 2006, 02:04 PM.

        Comment


        • #5
          Re: Decryption ??

          Thanks for the help.

          jamie
          All my answers were extracted from the "Big Dummy's Guide to the As400"
          and I take no responsibility for any of them.

          www.code400.com

          Comment


          • #6
            Re: Decryption ??

            Hi,

            for additional information:
            Column Encryption in IBM DB2 UDB for iSeries
            by Kent Milligan

            Birgitta
            Attached Files

            Comment


            • #7
              Re: Decryption ??

              I also added an RPGLE version of encryption/decryption to the tips section.
              It was written by Carsten Flensburg.


              Carsten Flensburg code
              All my answers were extracted from the "Big Dummy's Guide to the As400"
              and I take no responsibility for any of them.

              www.code400.com

              Comment


              • #8
                Re: Decryption ??

                This is a small inconvenience. Is there a fix or work-around if I want to save encrypted data to existing char fields?

                ...Actually saving is not the problem. The read-back is the issue.

                PHP Code:
                Select                              
                Decrypt_Char
                (CharFld)                
                from MyFile WHERE key 'TEST'                     

                Argument 01 of function DECRYPT_CHAR not valid
                Last edited by itp; January 30th, 2008, 04:41 PM.

                Comment


                • #9
                  Re: Decryption ??

                  Marty you ever get this working?

                  can you do an alter table on the field?

                  ALTER TABLE mylib/myfile ALTER COLUMN
                  myfield SET DATA TYPE char( 5) FOR BIT DATA
                  All my answers were extracted from the "Big Dummy's Guide to the As400"
                  and I take no responsibility for any of them.

                  www.code400.com

                  Comment


                  • #10
                    Re: Decryption ??

                    Indeed I could, but I would not be very popular modifying the structure of the Customer Master table on a Friday afternoon.

                    I faked it up with a simple %XLATE.

                    Comment


                    • #11
                      Re: Decryption ??

                      big-o-chicken
                      All my answers were extracted from the "Big Dummy's Guide to the As400"
                      and I take no responsibility for any of them.

                      www.code400.com

                      Comment

                      Working...
                      X