Added ability to change keylength. See #25
Added ability to change keylength. See #25

--- a/lib/crypto.php
+++ b/lib/crypto.php
@@ -28,6 +28,16 @@
 }
 
 
+
+/** Get the system configured keyLength
+*
+*/
+function getKeyLength(){
+  if (!$this->cipher){
+  $this->loadConfig();
+  }
+return $this->cipher->keyLength;
+}
 
 
 /** XOR functions Although the keys currently used are symmetric, 
@@ -211,16 +221,21 @@
 *
 * @return
 */
-function addKey(&$newkey,$newid){
+function addKey(&$newkey,$newid,$klength = false){
 
 
 $this->loadConfig();
 
+if (!$klength || empty($klength) || $klength < $this->cipher->keyLength){
+  $klength = $this->cipher->keyLength;
+}
+
+
 // Trim to the required keylength
-$newkey = substr( $newkey, 0,$this->cipher->keyLength);
+$newkey = substr( $newkey, 0, $klength);
 
 $cryptconf = fopen(getcwd() . '/conf/crypto.php','a');
-$str = "\n\$crypt->Cre$newid = '" . str_replace("'",'"',$newkey) . "';\n";
+$str = "\n\$crypt->Cre$newid = '" . str_replace("'",'"',$newkey) . "';";
 fwrite($cryptconf,$str);
 
 unset($newkey);

--- a/lib/includes/gatherEntropy.php
+++ b/lib/includes/gatherEntropy.php
@@ -11,7 +11,9 @@
 
 defined('_CREDLOCK') or die;
 
-
+if (!$crypt){
+  $crypt = new Crypto;
+}
 
 
 // Are we processing the generated or outputting the field
@@ -22,7 +24,7 @@
 
 $entropyseed = mt_rand(1000,999000);
 
-$x = 1100;
+$x = BTMain::getVar('kLength');
 
 
 
@@ -50,13 +52,6 @@
 
 $newkey = $entropyseed . $prkey . $entropy . $seed;
 
-
-
-if (!$crypt){
-$crypt = new Crypto;
-}
-
-
 $newkey = $crypt->encrypt($newkey,'ONEWAY',$ecrypt);
 
 
@@ -75,6 +70,9 @@
 
 
 ?>
+<label for="keyLength">Key Length</label>
+<input id="keyLength" type="text" name="kLength" value="<?php echo $crypt->getKeyLength();?>">
+
 <div id="EntropyGeneration">
 
 <div class='EntropyDiv' id="ClickDiv" title="Move your around mouse randomly whilst clicking. Box will turn green when sufficient clicks have been registered"></div>

--- a/views/Creds/addtype.php
+++ b/views/Creds/addtype.php
@@ -39,7 +39,9 @@
 include('lib/includes/gatherEntropy.php');
 unset($submitted);
  
-if(!$crypt->addKey($newkey,$newid)){
+$klength = BTMain::getVar('kLength');
+
+if(!$crypt->addKey($newkey,$newid,$klength)){
 
 
 $notifications->setNotification("KeyGenerationFailed");