Kbase P118786: How to use the ENCRYPT and DECRYPT functions
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  3/15/2011 |
|
Status: Verified
GOAL:
How to use the ENCRYPT and DECRYPT functions
GOAL:
Sample 4GL program using the ENCRYPT and DECRYPT functions
FACT(s) (Environment):
OpenEdge 10.x
FIX:
The following two procedures use the AES encrypting algorithm on OFB mode with 128 bit key. The binary key and the encrypted data are passed between procedures using shared variables.
/********************encrypt.p****************************/
DEFINE NEW SHARED VARIABLE binary-key AS RAW.
DEFINE VARIABLE clear-text AS CHARACTER INIT "Test".
DEFINE NEW SHARED VARIABLE crypto-value AS RAW.
DEFINE VARIABLE encrypted-text AS CHARACTER NO-UNDO.
binary-key = GENERATE-RANDOM-KEY.
SECURITY-POLICY:SYMMETRIC-ENCRYPTION-ALGORITHM = "AES_OFB_128".
SECURITY-POLICY:SYMMETRIC-ENCRYPTION-KEY = binary-key.
SECURITY-POLICY:SYMMETRIC-ENCRYPTION-IV = ?.
crypto-value = Encrypt (clear-text).
encrypted-text = BASE64-ENCODE(crypto-value).
MESSAGE "Encrypted Message:" encrypted-text
VIEW-AS ALERT-BOX INFO BUTTONS OK.
RUN decrypt.p.
/*********************decrypt.p****************************/
DEFINE SHARED VARIABLE binary-key AS RAW.
DEFINE VARIABLE decrypted-text AS CHARACTER.
DEFINE SHARED VARIABLE crypto-value AS RAW.
SECURITY-POLICY:SYMMETRIC-ENCRYPTION-ALGORITHM = "AES_OFB_128".
SECURITY-POLICY:SYMMETRIC-ENCRYPTION-KEY = binary-key.
SECURITY-POLICY:SYMMETRIC-ENCRYPTION-IV = ?.
decrypted-text = GET-STRING(DECRYPT (crypto-value),1).
MESSAGE "Decrypted Message: " decrypted-text
VIEW-AS ALERT-BOX INFO BUTTONS OK.