MIDRANGE dot COM Mailing List Archive



Home » MIDRANGE-L » December 2011

Re: Encryption for Dummies?



fixed

On 16-Dec-2011 10:21 , James Lampert wrote:
Gary Thompson wrote:
On 16-Dec-2011 08:35 , James Lampert wrote:
It seems that I'm going to need to encrypt a piddling 24-byte
"OAuth Consumer Secret" (one per installation, on the
installation's hardware).
Can anybody point me to some sample code for calling the
encryption/decryption APIs? I've now done HMAC-SHA1 signatures,
with an API call, but not actual encryption/decryption.

Can you get by with the encryption offered by DB2 SQL ? The
Reference manual has simple examples, look for ENCRYPT and DECRYPT

It's almost certainly not going to be stored in a database file, as
there is no practical reason to waste 36k to store (maybe) 32 bytes.
(It's ridiculous enough to waste 8k on storing them in a *DTAARA!)
So how would SQL encryption even apply?


The SQL is a language which provides support for parameters, result sets, and embedding in another language. The SQL will gladly set a value from a SQL statement in a variety of ways using those features, as a variable in a program irrespective the existence of any user-created database file. The following code snippet shows a string in variable StrOrig being encrypted into the variable StrEncrypt and then decrypted into the variable StrDecrypt. And although having no validation of SQLstate on any request and including the visible password, should be sufficient to show that no database file is required to invoke the cryptographic capabilities using just the SQL [and its scalars as the API] to get the string encrypted then decrypted. The SQL product need not be installed on any system on which the compiled program runs. However there ¿may be requirements? for what level of Cryptographic capabilities are installed per: "_Administration of encrypted data:_ Encrypted data can only be decrypted on servers that support the decryption functions that correspond to the ENCRYPT_RC2 function." from the notes in the documentation for that SQL scalar.

<code>

h dftactgrp(*no)
D StrOrig S 24A Varying
D StrDecrypt S 24A Varying
D StrEncrypt S SQLTYPE(VARBINARY:48)
D Pwd S 127A Varying
C/free
Exec SQL
Set Option Commit=*NONE, DatFmt=*ISO
;
StrOrig='My *secret* value';
Pwd= 'My password';
Exec SQL
VALUES encrypt(:StrOrig, :Pwd) INTO :StrEncrypt
;
Exec SQL
VALUES decrypt_char(:StrEncrypt, :Pwd) INTO :StrDecrypt
;
DSPLY StrDecrypt ;
*inlr = *on;

</code>

Regards, Chuck





Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2014 by MIDRANGE dot COM and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available here. If you have questions about this, please contact