Permalink
Browse files

reworked examples, keypair generator, examples now use pregenerated keys

  • Loading branch information...
1 parent a3ee011 commit c3f7dc04801ef122382641f501fb9abfb1123bcf @HazAT committed May 17, 2011
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -15,76 +15,54 @@
font-size:12px;
}
</style>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
+ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="../../jquery.jcryption.js" ></script>
<script type="text/javascript">
-
- $.fn.fillInForm = function() {
- $(this).find("a[href='#fillWithSamples']").click(function() {
- $parentForm = $(this).closest("form");
- $parentForm.find(":radio:eq(0)").attr("checked","checked");
- $parentForm.find("input[name='Firstname']").val("John");
- $parentForm.find("input[name='Lastname']").val("Wayne");
- $parentForm.find("input[name='Email']").val("john@wayne.cc");
- $parentForm.find(":checkbox:eq(2)").attr("checked","checked");
- $parentForm.find("select[name='age']").val("over 30");
- $parentForm.find("select[name='likes[]']").children("option:eq(0),option:eq(1),option:eq(3)").attr("selected","selected")
- return false;
- });
- };
-
$(function() {
- // Just the from filling code
- $("#normal").fillInForm();
- $(":input").removeAttr("disabled");
- // --------------------------
-
$("#normal").jCryption();
});
</script>
</head>
<body>
<form id="normal" class="general" action="main.php" method="post"> <fieldset>
-
- <strong><a href="#fillWithSamples" style="color:#000000;">fill with samples &raquo;</a></strong>
<table border="0" cellspacing="5" cellpadding="0">
<tbody>
<tr>
<td>Sex:</td>
- <td><input class="radio" name="Sex" type="radio" value="male" />Male
+ <td><input class="radio" name="Sex" type="radio" value="male" checked="checked" />Male
<input class="radio" name="Sex" type="radio" value="female" />Female</td>
</tr>
<tr>
<td>Firstname:</td>
- <td><input class="text" name="Firstname" type="text" /></td>
+ <td><input class="text" name="Firstname" type="text" value="John" /></td>
</tr>
<tr>
<td>Lastname:</td>
- <td><input class="text" name="Lastname" type="text" /></td>
+ <td><input class="text" name="Lastname" type="text" value="Wayne" /></td>
</tr>
<tr>
<td>E-Mail:</td>
- <td><input class="text" name="Email" type="text" /></td>
+ <td><input class="text" name="Email" type="text" value="john@wayne.com" /></td>
</tr>
<tr>
<td>What would you like to eat?</td>
- <td><input class="checkbox" name="Food[]" type="checkbox" value="pizza" />Pizza
+ <td><input class="checkbox" name="Food[]" type="checkbox" value="pizza" checked="checked" />Pizza
<input class="checkbox" name="Food[]" type="checkbox" value="hamburger" />Hamburger
- <input class="checkbox" name="Food[]" type="checkbox" value="salad" />Salad
+ <input class="checkbox" name="Food[]" type="checkbox" value="salad" checked="checked" />Salad
<input class="checkbox" name="Food[]" type="checkbox" value="steak" />Steak</td>
</tr>
<tr>
<td>Age:</td>
- <td><select name="age"> <option value="under 18">under 18</option> <option value="over 18">over 18</option> <option value="over 30">over 30</option> </select></td>
+ <td><select name="age"> <option value="under 18" selected="selected">under 18</option> <option value="over 18">over 18</option> <option value="over 30">over 30</option> </select></td>
</tr>
<tr valign="top">
<td valign="top">I like (you can select more than one):</td>
- <td><select name="likes[]" size="5" multiple="multiple"> <option value="Michael Jackson">Michael Jackson</option> <option value="rainy wheater">rainy wheater</option> <option value="a hot summer">a hot summer</option> <option value="small cats">small cats</option> <option value="funny movies">funny movies</option> <option value="I like everything">I like everything</option> </select></td>
+ <td><select name="likes[]" size="5" multiple="multiple"> <option value="Michael Jackson">Michael Jackson</option> <option value="rainy wheater" selected="selected">rainy wheater</option> <option value="a hot summer">a hot summer</option> <option value="small cats" selected="selected">small cats</option> <option value="funny movies">funny movies</option> <option value="I like everything" selected="selected">I like everything</option> </select></td>
</tr>
<tr>
<td></td>
@@ -1,10 +1,11 @@
<?php
session_start();
require_once("../../jcryption.php");
-$keyLength = 256;
+$keyLength = 1024;
$jCryption = new jCryption();
if(isset($_GET["generateKeypair"])) {
- $keys = $jCryption->generateKeypair($keyLength);
+ require_once("../../100_1024_keys.inc.php");
+ $keys = $arrKeys[mt_rand(0,100)];
$_SESSION["e"] = array("int" => $keys["e"], "hex" => $jCryption->dec2string($keys["e"],16));
$_SESSION["d"] = array("int" => $keys["d"], "hex" => $jCryption->dec2string($keys["d"],16));
$_SESSION["n"] = array("int" => $keys["n"], "hex" => $jCryption->dec2string($keys["n"],16));
@@ -15,89 +15,71 @@
font-size:12px;
}
</style>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
+ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="../../jquery.jcryption.js" ></script>
<script type="text/javascript">
-
- $.fn.fillInForm = function() {
- $(this).find("a[href='#fillWithSamples']").click(function() {
- $parentForm = $(this).closest("form");
- $parentForm.find(":radio:eq(0)").attr("checked","checked");
- $parentForm.find("input[name='Firstname']").val("John");
- $parentForm.find("input[name='Lastname']").val("Wayne");
- $parentForm.find("input[name='Email']").val("john@wayne.cc");
- $parentForm.find(":checkbox:eq(2)").attr("checked","checked");
- $parentForm.find("select[name='age']").val("over 30");
- $parentForm.find("select[name='likes[]']").children("option:eq(0),option:eq(1),option:eq(3)").attr("selected","selected")
- return false;
- });
- };
-
$(function() {
var $status = $('<div id="status" style="margin-top:15px;"><img src="loading.gif" alt="Loading..." title="Loading..." style="margin-right:15px;" /><span>Encrypting</span></div>').hide();
$("#submitButton").parent().append($status);
- $("#callbackForm").jCryption({
+ $("#normal").jCryption({
beforeEncryption:function() {
$status.show();
return true;
}
- }).find("fieldset").fillInForm();
-
- $(":input").removeAttr("disabled");
+ });
});
</script>
</head>
- <body><form action="main.php" method="post" id="callbackForm" class="general">
- <fieldset>
- <strong><a href="#fillWithSamples" style="color:#000000;">fill with samples &raquo;</a></strong>
+ <body>
+ <form id="normal" class="general" action="main.php" method="post"> <fieldset>
<table border="0" cellspacing="5" cellpadding="0">
<tbody>
<tr>
<td>Sex:</td>
- <td><input class="radio" name="Sex" type="radio" value="male" />Male
+ <td><input class="radio" name="Sex" type="radio" value="male" checked="checked" />Male
<input class="radio" name="Sex" type="radio" value="female" />Female</td>
</tr>
<tr>
<td>Firstname:</td>
- <td><input class="text" name="Firstname" type="text" /></td>
+ <td><input class="text" name="Firstname" type="text" value="John" /></td>
</tr>
<tr>
<td>Lastname:</td>
- <td><input class="text" name="Lastname" type="text" /></td>
+ <td><input class="text" name="Lastname" type="text" value="Wayne" /></td>
</tr>
<tr>
<td>E-Mail:</td>
- <td><input class="text" name="Email" type="text" /></td>
+ <td><input class="text" name="Email" type="text" value="john@wayne.com" /></td>
</tr>
<tr>
<td>What would you like to eat?</td>
- <td><input class="checkbox" name="Food[]" type="checkbox" value="pizza" />Pizza
+ <td><input class="checkbox" name="Food[]" type="checkbox" value="pizza" checked="checked" />Pizza
<input class="checkbox" name="Food[]" type="checkbox" value="hamburger" />Hamburger
- <input class="checkbox" name="Food[]" type="checkbox" value="salad" />Salad
+ <input class="checkbox" name="Food[]" type="checkbox" value="salad" checked="checked" />Salad
<input class="checkbox" name="Food[]" type="checkbox" value="steak" />Steak</td>
</tr>
<tr>
<td>Age:</td>
- <td><select name="age"> <option value="under 18">under 18</option> <option value="over 18">over 18</option> <option value="over 30">over 30</option> </select></td>
+ <td><select name="age"> <option value="under 18" selected="selected">under 18</option> <option value="over 18">over 18</option> <option value="over 30">over 30</option> </select></td>
</tr>
<tr valign="top">
<td valign="top">I like (you can select more than one):</td>
- <td><select name="likes[]" size="5" multiple="multiple"> <option value="Michael Jackson">Michael Jackson</option> <option value="rainy wheater">rainy wheater</option> <option value="a hot summer">a hot summer</option> <option value="small cats">small cats</option> <option value="funny movies">funny movies</option> <option value="I like everything">I like everything</option> </select></td>
+ <td><select name="likes[]" size="5" multiple="multiple"> <option value="Michael Jackson">Michael Jackson</option> <option value="rainy wheater" selected="selected">rainy wheater</option> <option value="a hot summer">a hot summer</option> <option value="small cats" selected="selected">small cats</option> <option value="funny movies">funny movies</option> <option value="I like everything" selected="selected">I like everything</option> </select></td>
</tr>
<tr>
<td></td>
- <td><input title="Submit" alt="Submit" name="submitButton" type="submit" value="Submit" class="submit" id="submitButton" /> <input title="Reset" alt="Reset" name="reset" type="reset" value="Reset" /></td>
+ <td><input title="Submit" alt="Submit" name="submitButton" id="submitButton" type="submit" value="Submit" class="submit" /> <input title="Reset" alt="Reset" name="reset" type="reset" value="Reset" /></td>
</tr>
</tbody>
- </table>
+ </table>
</fieldset>
</form>
</body>
@@ -2,11 +2,12 @@
session_start();
require_once("../../jcryption.php");
-$keyLength = 256;
+$keyLength = 1024;
$jCryption = new jCryption();
if(isset($_GET["generateKeypair"])) {
- $keys = $jCryption->generateKeypair($keyLength);
+ require_once("../../100_1024_keys.inc.php");
+ $keys = $arrKeys[mt_rand(0,100)];
$_SESSION["e"] = array("int" => $keys["e"], "hex" => $jCryption->dec2string($keys["e"],16));
$_SESSION["d"] = array("int" => $keys["d"], "hex" => $jCryption->dec2string($keys["d"],16));
$_SESSION["n"] = array("int" => $keys["n"], "hex" => $jCryption->dec2string($keys["n"],16));
@@ -1,17 +1,18 @@
<?php
session_start();
require_once("../../jcryption.php");
- $keyLength = 256;
+ $keyLength = 1024;
$jCryption = new jCryption();
if(isset($_GET["generateKeypair"])) {
- $keys = $jCryption->generateKeypair($keyLength);
+ require_once("../../100_1024_keys.inc.php");
+ $keys = $arrKeys[mt_rand(0,100)];
$_SESSION["e"] = array("int" => $keys["e"], "hex" => $jCryption->dec2string($keys["e"],16));
$_SESSION["d"] = array("int" => $keys["d"], "hex" => $jCryption->dec2string($keys["d"],16));
$_SESSION["n"] = array("int" => $keys["n"], "hex" => $jCryption->dec2string($keys["n"],16));
echo '{"e":"'.$_SESSION["e"]["hex"].'","n":"'.$_SESSION["n"]["hex"].'","maxdigits":"'.intval($keyLength*2/16+3).'"}';
} else {
$var = $jCryption->decrypt($_POST['jCryption'], $_SESSION["d"]["int"], $_SESSION["n"]["int"]);
- echo $var;
+ echo urldecode($var);
}
?>
@@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Example 1</title>
+ <title>String Encryption</title>
<style type="text/css">
html,body {
margin:0;
@@ -15,7 +15,7 @@
font-size:12px;
}
</style>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
+ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="../../jquery.jcryption.js"></script>
<script type="text/javascript">
var $loader = $('<img src="loading.gif" alt="Loading..." title="Loading..." style="margin-right:15px;" />');
@@ -30,7 +30,7 @@
});
$("#encrypt").click(function() {
- $.jCryption.encrypt($("#toEncrypt").val(),keys,function(encrypted) {
+ $.jCryption.encrypt(encodeURIComponent($("#toEncrypt").val()),keys,function(encrypted) {
$("#toDecrypt").val(encrypted);
});
});
View
@@ -0,0 +1,21 @@
+<?php
+
+require_once("jcryption.5.3.php");
+
+$keyLength = 1024;
+$jCryption = new jCryption();
+
+$numberOfPairs = 100;
+$arrKeyPairs = array();
+
+for ($i=0; $i < $numberOfPairs; $i++) {
+ $arrKeyPairs[] = $jCryption->generateKeypair($keyLength);
+}
+
+$file = array();
+$file[] = '<?php';
+$file[] = '$arrKeys = ';
+$file[] = var_export($arrKeyPairs, true);
+$file[] = ';';
+
+file_put_contents($numberOfPairs . "_". $keyLength . "_keys.inc.php", implode("\n", $file));
View
@@ -19,7 +19,7 @@
* @author Daniel Griesser <daniel.griesser@jcryption.org>
* @copyright 2011 Daniel Griesser
* @license http://www.php.net/license/3_0.txt PHP License 3.0
-* @version 1.1
+* @version 1.2
* @link http://jcryption.org/
*/
class jCryption {
View
@@ -1,5 +1,5 @@
/*
-* jCryption JavaScript data encryption v1.1
+* jCryption JavaScript data encryption v1.2
* http://www.jcryption.org/
*
* Copyright (c) 2010 Daniel Griesser
@@ -36,8 +36,8 @@
$submitElement.bind(base.options.submitEvent,function() {
$(this).attr("disabled",true);
if(base.options.beforeEncryption()) {
- $.jCryption.getKeys(base.options.getKeysURL,function(keys) {
- $.jCryption.encrypt(base.$el.serialize(),keys,function(encrypted) {
+ $.jCryption.getKeys(base.options.getKeysURL, function(keys) {
+ $.jCryption.encrypt(base.$el.serialize(), keys,function(encrypted) {
$encryptedElement.val(encrypted);
$(base.$el).find(base.options.formFieldSelector).attr("disabled",true).end().append($encryptedElement).submit();
});
@@ -52,17 +52,7 @@
};
$.jCryption.getKeys = function(url,callback) {
- var base = this;
- base.getKeys = function() {
- $.getJSON(url,function(data){
- keys = new base.jCryptionKeyPair(data.e,data.n,data.maxdigits);
- if($.isFunction(callback)) {
- callback.call(this, keys);
- }
- });
- };
-
- base.jCryptionKeyPair = function(encryptionExponent, modulus, maxdigits) {
+ var jCryptionKeyPair = function(encryptionExponent, modulus, maxdigits) {
setMaxDigits(parseInt(maxdigits,10));
this.e = biFromHex(encryptionExponent);
this.m = biFromHex(modulus);
@@ -71,7 +61,12 @@
this.barrett = new BarrettMu(this.m);
};
- base.getKeys();
+ $.getJSON(url,function(data){
+ var keys = new jCryptionKeyPair(data.e,data.n,data.maxdigits);
+ if($.isFunction(callback)) {
+ callback.call(this, keys);
+ }
+ });
};
$.jCryption.encrypt = function(string,keyPair,callback) {
Oops, something went wrong.

0 comments on commit c3f7dc0

Please sign in to comment.