Tips and Techniques: Encrypting Text

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Encrypting data in RPG IV is becoming more and more necessary. IBM supplies two methods for encrypting text:

  • The CIPHER MI instruction—This instruction has been around forever and allows you to encrypt a string of text using DES, AES, or RC4 encryption methods, among others.
  • The Qc3xxxxx encryption APIs—These APIs do it all, from encryption (beginning with V5R3) to key management (on V5R4). They are bit complex, so if you're interested, look for my past articles on this topic.

If you have RPG xTools on your system, you have a third choice. RPG xTools includes several encryption subprocedures that make encrypting data within RPG IV as easy as this:

  callp     aesEncrypt(ccnbr : %size(ccnbr): password);

The aesEncrypt procedure encrypts the data in the CCNBR field using AES encryption and the provided password or "cipher key."

One problem with AES encryption is that it requires the data length to be in multiples of 16, 24, or 32 bytes. Therefore a 10-position field cannot be encrypted unless it is first moved into a 16-position field and that 16-position field is encrypted.

RPG xTools includes RC4 encryption as well as AES. Unlike AES, RC4 encryption doesn't care how long or short a field is; it will encrypt it. To encrypt with RC4 encryption in RPG IV using xTools, the following can be coded:

  callp     rc4Encrypt(ccnbr : %size(ccnbr): password);

Note that the interface is effectively identical to the aesEncrypt procedure. This is one of the areas in which the Qc3xxxxx APIs have an issue: There are so many formats and control blocks that even experienced programmers shy away from them until they can take the time to study them to make sure they implement things correctly.

In addition to data encryption, RPG xTools also supports hash generations or "message digests." Currently, RPG xTools supports MD-5 (128-bit) and Whirlpool (512-bit) hash.

These routines produce a unique value (or "signature" as it is sometimes called) from a string of text. Many people use these hash routines to produce a message digest of a password. Then, the message digest or hash is used as the password to encrypt the data. This ensures that if you decide your password is something obvious, such as Rosebud, the actual password used to encrypt the data would be the 512-bit hash generated from the word Rosebud. Thus, guessing the password can be much more difficult.

More and more, encryption is becoming an everyday requirement. If you aren't using encryption today, you probably will be in the next 12 to 24 months. Start looking into it. You'll find plenty of tools to help you, including the Qc3xxxxx APIs, the CIPHER MI instruction set, and RPG xTools wrapper procedures.

Bob Cozzi is a programmer/consultant, writer/author, and software developer of the RPG xTools, a popular add-on subprocedure library for RPG IV. His book The Modern RPG Language has been the most widely used RPG programming book for nearly two decades. He, along with others, speaks at and runs the highly-popular RPG World conference for RPG programmers.

BOB COZZI

Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.


MC Press books written by Robert Cozzi available now on the MC Press Bookstore.

RPG TnT RPG TnT
Get this jam-packed resource of quick, easy-to-implement RPG tips!
List Price $65.00

Now On Sale

The Modern RPG IV Language The Modern RPG IV Language
Cozzi on everything RPG! What more could you want?
List Price $99.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: