From 8d55ae4b6da3a20a7cd7cfe24887e170ea94c7f5 Mon Sep 17 00:00:00 2001 From: anomen Date: Wed, 21 Sep 2011 21:52:57 +0200 Subject: [PATCH] www-apps/pmwiki - cookbook - AesCrypt --- .../org/pmwiki/cookbook/aescrypt/PmWikiTest.java | 3 ++ www-apps/pmwiki/cookbook/AesCrypt/aes.js | 6 +--- www-apps/pmwiki/cookbook/AesCrypt/aescrypt.php | 34 +++++++++++++--------- www-apps/pmwiki/cookbook/AesCrypt/readme.txt | 25 +++++++++++++--- 4 files changed, 45 insertions(+), 23 deletions(-) diff --git a/www-apps/pmwiki/cookbook/AesCrypt/JavaAesCryptTest/src/test/java/org/pmwiki/cookbook/aescrypt/PmWikiTest.java b/www-apps/pmwiki/cookbook/AesCrypt/JavaAesCryptTest/src/test/java/org/pmwiki/cookbook/aescrypt/PmWikiTest.java index 1b54488..97a2c5d 100644 --- a/www-apps/pmwiki/cookbook/AesCrypt/JavaAesCryptTest/src/test/java/org/pmwiki/cookbook/aescrypt/PmWikiTest.java +++ b/www-apps/pmwiki/cookbook/AesCrypt/JavaAesCryptTest/src/test/java/org/pmwiki/cookbook/aescrypt/PmWikiTest.java @@ -54,6 +54,9 @@ public class PmWikiTest extends TestCase { assertEquals("abc", AesCrypto.decryptFromBase64RawKey("1ohjTsnJycmALuk=", keyData)); + assertEquals(" Encrypt this text ", + AesCrypto.decryptFromBase64RawKey("jvJ5Tnl5eXnpdK89gmpkiWxjkmi73OoGc72C", keyData)); + } } diff --git a/www-apps/pmwiki/cookbook/AesCrypt/aes.js b/www-apps/pmwiki/cookbook/AesCrypt/aes.js index 61f784d..488b5b6 100644 --- a/www-apps/pmwiki/cookbook/AesCrypt/aes.js +++ b/www-apps/pmwiki/cookbook/AesCrypt/aes.js @@ -305,14 +305,10 @@ AesCtr.kdf_aes = function(password, nBits) { for (var i=0; i @@ -54,7 +53,7 @@ function aesClick() { while ((tpart.length % padding) > 0) { tpart = tpart.concat(' '); } - alert(tpart); + tarr +=AesCtr.encrypt(tpart,tpass,256); tarr += ' '; tarr += markup_end; @@ -88,14 +87,16 @@ function decAesClick(elem) { function registerAesEvent() { var formElement = document.getElementById('text').parentNode; - alert(formElement.nodeValue); + //alert(formElement.nodeValue); + + // TODO: add protection handler to save buttons } if ( document.addEventListener ) { -// window.addEventListener( 'load', registerAesEvent, false ); + window.addEventListener( 'load', registerAesEvent, false ); } else if ( document.attachEvent ) { -// window.attachEvent( 'onload', registerAesEvent ); + window.attachEvent( 'onload', registerAesEvent ); } // ]]> @@ -103,16 +104,21 @@ if ( document.addEventListener ) { "; Markup('aescrypt', - 'inline', - "/\\(:aes\\s+(.*?)\s*:\\)/se", + '_begin', + "/\\Q$AesCryptCipherToken\\E\\s*(.*?)\\s*\\Q$AesCryptEndToken\\E/se", "'\n'.'$1[Decrypt]'"); if ($action == 'edit') { - $GUIButtons['aescrypt'] = array(750, '', '', '', - ''); - - $GUIButtons['aescryptDebug'] = array(1750, '', '', '', - ''); + if ($EnableGUIButtons) { + $GUIButtons['aescrypt'] = array(750, '', '', '', + ''); + } else { + $MessagesFmt[] = ""; + } } + // DEV + $GUIButtons['aescryptDebug'] = array(1750, '', '', '', + ''); + diff --git a/www-apps/pmwiki/cookbook/AesCrypt/readme.txt b/www-apps/pmwiki/cookbook/AesCrypt/readme.txt index a3b21b9..d0e0dda 100644 --- a/www-apps/pmwiki/cookbook/AesCrypt/readme.txt +++ b/www-apps/pmwiki/cookbook/AesCrypt/readme.txt @@ -3,7 +3,8 @@ !!!Alternative version by [[~Anomen]]. : git repo : http://repo.or.cz/w/anomen-overlay.git/tree/HEAD:/www-apps/pmwiki/cookbook/AesCrypt -My version fixes several problems: + +This version fixes several problems: * non-standard and weak (only 128bit) key derivation function replaced with SHA-256 * rewritten low quality javascript code * created alternative implementation - see Java testing application @@ -16,8 +17,24 @@ My version fixes several problems: * random 64bit nonce is extended to 128bit by appending 64bit counter (zeroes) * key derivation algorithm (configurable by $AesCryptKDF) ** sha256 (SHA-256 hash of password) -** aes (encrypt password with AES) +** aes (encrypt password with AES, compatible with original aescrypt-0.1 recipe) ** pbkdf2 (not yet implemented) * plaintext is encripted using AES-256 in CTR mode -* output is concatenation of upper 64 bits of nonce and ciphertext -* output is Base64-encoded +* output is Base64-encoded concatenation of upper 64 bits of nonce and ciphertext + +To replace previous version use: +[@ +$AesCryptKDF='aes'; +$AesCryptPlainToken='(:aescrypt:) [='; +$AesCryptCipherToken='(:aescrypted:) [='; +$AesCryptEndToken='=]'; +require_once('cookbook/aescrypt.php'); +@] + +!!Configuration +: $AesCryptKDF : aes, sha256, pbkdf2; +: $AesCryptPlainToken : starting token for plaintext +: $AesCryptCipherToken : starting token for ciphertext +: $AesCryptEndToken : closing token +: $AesCryptPadding : size of padding block +: $EnableGUIButtons : affects rendering of Encrypt button (do not modify it after including aescrypt.php) -- 2.11.4.GIT