I've poked around a bit in SuperSearch and on Google, but I either I can't seem to hit on the right terms, or no one is discussing this.

I'm thinking about writing a cryptographic GUI (probably Tk) application in Perl; the plaintext will obviously have to be in memory at some point so that it can be displayed. However, once the user no longer needs to see the plaintext, I'd like to ensure that it gets entirely cleared from memory so that it cannot be examined later without decrypting it again.

Additionally, I'm concerned about the plaintext ending up in swap.

Is there anything I can do in Perl to ensure this kind of memory security? Or will I have to dust the rust off my C skills to get this to work?

Am I barking up the wrong tree by doing something like:

my $plaintext = decrypt($ciphertext, $key); # .. display plain text, wait for user to close .. $key = '0' x length($key); $plaintext = '0' x length($plaintext);
?

Thanks in advance to anyone who can point me in the right direction!

<radiant.matrix>
Ramblings and references
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet

In reply to Can I do secure memory management in Perl scripts for cryptographic applications? by radiantmatrix

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.