ClarionX Updates

    follow me on Twitter

    Subscribe

    Enter your email address:

    Delivered by FeedBurner

    Blog powered by TypePad
    Member since 08/2006

    May 29, 2007

    Reading Base64 ...

    This is the first article in an Internet Protocol/encoding Series...As developers we will at one time or another need to read base64 encoded data....heres my take...

    Base64 is used to encode binary files in a text format suitable to be encapsulated in text documents. One interesting thing about base 64 is that it is one of the only data representation
    schemes in modern use that doesn’t encrypt or compress the data. It just represents data
    in a different form.

    The solution to this problem was to create a data representation protocol that would allow
    binary data to be encapsulated within another document. The defacto standard for doing
    this is called base 64. In fact, some applications use base 64 as an encryption technique,
    albeit a weak one. Basic authentication over the Internet encrypts the username-password
    using base 64.

    Here is a simple base64 decoder algorithm that has been very useful over the years...

    base64decode PROCEDURE(STRING b64)

    b64chars STRING('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/')

    oString ANY

    CODE

    oString = '' !Dont use CLEAR it will cause a GPF on an ANY Variable

    ! Base64 strings especially those from emails can contain carriage returns and tabs these must be removed before decoding....

    b64 = StringReplace(b64,CHR(9),'')
    b64 = StringReplace(b64,CHR(10),'')
    b64 = StringReplace(b64,CHR(13),'')

    ! Base64 strings are groups of four characters and need to be stepped through by 4....

    LOOP i# = 1 TO LEN(CLIP(b64)) BY 4

    !Create a 24 bit Number by bit shifting the four chars values by  6 bit segments...

    BigNumber# = BSHIFT(INSTRING(b64[i#],b64chars,1,1)-1,18) + BSHIFT(INSTRING(b64[i#+1],b64chars,1,1)-1,12) + BSHIFT(INSTRING(b64[i#+2],b64chars,1,1)-1,6) + (INSTRING(b64[i#+3],b64chars,1,1)-1)

    !Extract the original 3 ascii chars by bit shifting in the other direction by 8 bit segments...

    Char1# = BAND(BSHIFT(BigNumber#,-16),11111111b)
    Char2# = BAND(BSHIFT(BigNumber#,-8),11111111b)
    Char3# = BAND(BigNumber#,11111111b)

    !handle trailing padding characters thus...and translate the character values...
    IF b64[i#+3] = '=' AND b64[i#+2] ~= '=' THEN
    oString = oString & CHR(Char1#)&CHR(Char2#)
    ELSIF b64[i#+3] = '=' AND b64[i#+2] = '=' THEN
    oString = oString & CHR(Char1#)
    ELSE
    oString = oString & CHR(Char1#)&CHR(Char2#)&CHR(Char3#)
    END
    !repeat operation for each group of four base64 chars

    END

    RETURN CLIP(oString)

    The result is the unencoded text or binary data....for more info on base64 like a encoding checkout RFC 3548...

    September 13, 2006

    Email Security...

    We all know that email is insecure.....

    But how do you offer some limited protection for plain text email content?

    The answer is to encode it as base64 and set the content disposition as inline. This will tell the email client that the section that is inline is plain text encoded to base64....and magically the conversion is done.

    What does this mean??? It means that content cannot be easily scraped or siphoned off....that's all....

    Example:

    Content-Disposition: inline
    Content-Transfer-Encoding: base64
    Content-Type: text/plain; charset="UTF8"
    MIME-Version: 1.0
    Date: Tue, 12 Sep 2006 18:34:42 UT
    To: jmoore@johnmo.com
    From: alert@johnmo.com
    Subject: Sales Alert

    CgpUaGUgZm9sbG93aW5nIHJlY2VudCBwcm9wZXJ0eSBsaXN0aW5ncyBtYXRjaGVkIHlvdXIKUmVh
    bCBFc3RhdGUgQWxlcnQgc2VhcmNoIGNyaXRlcmlhLgoKCgoNLS0tLS0tLS0tLS0tLS0tLS0tLS0t
    LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tCgoN
    T2ZmZXJzIG92ZXIgJDYyNS....

    The plain text section has been base64 encoded for a little privacy....

    ClarionX is a proud contributor to DevDawn.com.

    August 31, 2006

    Easy Outlook Automation

    Outlook Automation in Clarion is simpler than you think!
    All you need is a window, an OCX control and a couple of hints and your off.
    Here is a few tips;
    1. The Outlook Object name is "Outlook.Application".
    2. First step is to Create a Namespace Object
    olns = ?OLE{'GetNamespace("MAPI")'}
    !olns is a CSTRING variable object which contains a reference to the namespace object.
    3. With the namespace object you can do the following;
    To get the number of top level folders.
    ?OLE{CLIP(olns)&'.Folders.Count'}
    4. When navigating through items in a folder the following approach can be used;
    NumItems# = OL{CLIP(objFolder)&'.Items.Count'}
    IF NumItems# > 0 THEN
    LOOP i# = 1 TO NumItems#
    To get the class of the item do this OL{CLIP(objFolder)&'.Items.Item('&CLIP(i#)&').Class'}
    Class is if its a ContactItem, AppointmentItem, TaskItem, NoteItem etc
    To get the entryid of the item do this OL{CLIP(objFolder)&'.Items.Item('&CLIP(i#)&').EntryId'}
    END
    END
    From there on any method that returns an object can be stored in a cstring and used as above.