PDA

View Full Version : How to: Blowfish Encryption - bf_encrypt(key, text, result)


aGorilla
05-27-06, 12:51 AM
Ok, they say you can use (http://smallbusiness.miva.com/support/docs/ScriptGuide_html/ScriptGuide.html) Blowfish Encryption (http://en.wikipedia.org/wiki/Blowfish_(cipher)), but searching through the mailing list, only finds a couple of failed attempts (http://www.google.com/search?q=miva+bf_encrypt)

Having done some work on porting the AES library, I had a hint that the problem was that you needed a specific key length. Not knowing how long it was, I figured I'd try a bunch (see code below).

That did the trick, once the key was 16 chars long, it showed the encrypted, and decrypted values.

<MvASSIGN NAME="l.key" VALUE="">
<MvASSIGN NAME="l.plaintext" VALUE="This is plain text.">

<MvASSIGN NAME="l.count" VALUE="0">
<MvASSIGN NAME="l.max" VALUE="128">
<MvWHILE EXPR="{l.count LT l.max}">
<MvASSIGN NAME="l.count" VALUE="{l.count + 1}">
<MvASSIGN NAME="l.key" VALUE="{l.key $ 'a'}">
<MvASSIGN NAME="l.worked" VALUE="{bf_encrypt(l.key, l.plaintext, l.encrypted)}">
<MvEVAL EXPR="{'Debug : ' $ l.key $ '<br>'}">
<MvIF EXPR="{l.worked}">
<MvASSIGN NAME="l.worked" VALUE="{bf_decrypt(l.key, l.encrypted, l.decrypted)}">
<MvEVAL EXPR="{'Debug encrypted: ' $ l.encrypted $ '<br>'}">
<MvEVAL EXPR="{'Debug decrypted: ' $ l.decrypted $ '<br>'}">
<MvWHILESTOP>
</MvIF>
</MvWHILE>