ENCRYPT64

From Pickwiki
Jump to navigationJump to search

HomePage>>SourceCode>>BasicSource>>ENCRYPT64

Sample code using the ENCRYPT function in Universe (U2). Note that ENCRYPT will output base64 that contains non-printable characters; they must be stripped out before decrypting.

      FUNCTION ENCRYPT64(TEXT)
*
      EQU ALGORITHM$ TO "RC4"
      EQU ACTION$ENCRYPT TO 1
      EQU ACTION$ENCRYPT.BASE64 TO 2
      EQU ACTION$DECRYPT TO 3
      EQU ACTION$DECRYPT.BASE64 TO 4
      EQU DATALOC$STRING TO 1
      EQU DATALOC$FILE TO 2
      EQU KEY$ TO "ABCDEFGHIJKLMNOP"
      EQU KEYLOC$DATA TO 1
      EQU KEYLOC$FILE TO 2
      EQU KEYACTION$ACTUAL.KEY TO 1
      EQU KEYACTION$DERIVE.KEY TO 2
      EQU SALT$ TO ""
      EQU IV$ TO ""
      EQU RESULTLOC$STRING TO 1
      EQU RESULTLOC$FILE TO 2
*
      IF UNASSIGNED(TEXT) THEN
         ABORTM "TEXT IS UNASSIGNED!"
      END
      IF TEXT = "" THEN
         RETURN ("")
      END
*
      RESULT = ""
*
      ERRCODE = ENCRYPT(ALGORITHM$, ACTION$ENCRYPT.BASE64,
         (TEXT), DATALOC$STRING,
         KEY$, KEYLOC$DATA, KEYACTION$ACTUAL.KEY,
         SALT$, IV$,
         RESULT, RESULTLOC$STRING)
*
      IF ERRCODE THEN
         ABORTM "ENCRYPT64: ERRCODE ":ERRCODE
      END
*
* get rid of non-printable characters
*
      RESULT = OCONV(RESULT, "MCP")
      CONVERT "." TO "" IN RESULT
*
* return to caller
*
      RETURN (RESULT)
   END

http://www.autopower.com/rgozar/pixel.gif