File:  [mozdev] / quickfilters / www / encrypt.html
Revision 1.5: download - view: text, annotated - select for diffs - revision graph
Sat Nov 10 12:35:16 2018 UTC (15 months, 1 week ago) by axel.grude
Branches: MAIN
CVS tags: HEAD
changed charset to UTF-8

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>quickFilters</title>
    <!-- LOCAL HEAD.TXT -->
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta content="text/css" http-equiv="Content-Style-Type" />
    <link rel="stylesheet" href="css/project_nav.css?v=4" type="text/css">
    <link rel="stylesheet" href="css/myProjects.css?v=23" type="text/css">
    <script src="script/premium.js"> </script>

  </head>  
<body>

	<!-- ####################### BEGIN MAIN CONTENT ########################## 
	<div id="main-content-no-nav">

      <table id="project-navigation">

        <tbody id="resources" class="project-navigations">
          <tr>
            <th scope="row"></th>
            <td class="navigation-list">
              <a href="index.html" class="first-item active">Home</a>
              <a href="installation.html">Installation</a>
              <a href="version.html">Version&nbsp;History</a>
              <a href="faq_tips.html">FAQ&nbsp;+&nbsp;Tips</a>
              <a href="donate.html">Support&nbsp;quickFilters!</a>
              <a href="screenshots.html">Screenshots</a>
              <a href="bugs.html">Bugs + Feature Requests</a>
              <a href="quickFilters.html">quickFilters</a>
              <a href="menuOnTop.html">Menu On Top</a>
            </td>
          </tr>
        </tbody>
      </table>	
			-->
	
		<div class="h2container">
			<h2 class="page-header" style="vertical-align:top;">License Encryption</h2>
		</div>

		<style type="text/css">
			spacer {
				width:4em;
			}
			.formContainer {
				vertical-align: top;
			}
			.formBox {
				border: 1px solid gray;
				border-top-right-radius: 1em;
				display: inline-block;
				margin-right: 1em;
				padding: 1em;
				position: relative;
			}
			.boxLabel {
				background: rgba(230,230,230,1);
				border: 1px solid gray;
				left: 1em;
				padding: 0.3em 1em;
				top: -14px; 
				position: absolute;
				cursor: pointer;
			}
			.buttonPanel {
				text-align: right;
			}
			.encryptionBox input[type=text] {
				width: 70em;
			}
			#personData input[type=text] {
				width: 20em;
			}
			.label {
				display: inline-block;
				min-width: 100px;
			}
			#maxDigits, #prefix, #keySize {
				width: 3em !important;
			}
			#licenseKey {
				font-size: 10pt;
				font-family: Consolas, Courier, monospace;
				width:95em;
				height:4em;
			}
		</style>

		<script type="text/javascript" src="script/encrypt.js?ver=1" charset="UTF-8">

		</script>

		<script type="text/javascript">

		// note: encryption keys have to be entered manually and are stored in a cookie
		//       as they are not for public consumption!
		const default_RSA_decryption= "1933eef03efab13188c903d69d293d4db35372620a0c26f23e1f805ba2d4e87",
				default_RSA_modulus     = "1ef94b8a38bcfecc0dc49517045dd7362b3e8181be290a4dc298c807b052297",
				default_RSA_keySize = "256",
				default_RSA_maxDigits = "35",
				domain_RSA_decryption   = "",
				domain_RSA_modulus      = "",
				domain_RSA_keySize = "512",
				domain_RSA_maxDigits = "67";
		var		dummy = 0, key_type=0;
				
		function onPageLoad() {
			key_type = 1;
			toggleEncryption();
			var now = new Date(),
					expiryDate = addDate(now, 1,'Y'),
					txtDate = expiryDate.getFullYear() + '-' + twoDigit(expiryDate.getMonth()+1) + '-' + twoDigit(expiryDate.getDate());
			document.getElementById('expiry').value = txtDate;	
			checkCookies();
		}		

		function toggleEncryption() {
			// change to domain encryption key
			key_type = (key_type==1) ? 0 : 1;
			switch (key_type) {
				case 0:
					document.getElementById('prefix').value = 'QI-';
					document.getElementById('modulo').value = default_RSA_modulus;
					document.getElementById('decryptionKey').value = default_RSA_decryption;
					document.getElementById('keySize').value = default_RSA_keySize;
					document.getElementById('maxDigits').value = default_RSA_maxDigits;
					document.getElementById('emailLabel').textContent='Email:';
					break;
				case 1:
					document.getElementById('prefix').value = 'QID-';
					document.getElementById('modulo').value = domain_RSA_modulus;
					document.getElementById('decryptionKey').value = domain_RSA_decryption;
					document.getElementById('keySize').value = domain_RSA_keySize;
					document.getElementById('maxDigits').value = domain_RSA_maxDigits;
					document.getElementById('emailLabel').textContent='* Domain:';
					break;
			}
			checkCookies(); // fill the correct decryption Key
		}

		/** removed from encryption script as these need to access form specific variables **/
		function createKey() {
			var keySize = parseInt(document.getElementById('keySize').value, 10);
			if (keySize) {
				// encryptionExponent, decryptionExponent, modulus
				var enc = document.getElementById('encryptionKey').value,
						dec = document.getElementById('decryptionKey').value,
						mod = document.getElementById('modulo').value,
						maxD = parseInt(document.getElementById('maxDigits').value);
				setMaxDigits(maxD);
				key = new RSAKeyPair(enc, dec, mod);
				return key;
			}
			return null;
		}

		function encrypt(LicenseKey) {
			var key = createKey(),
					t1 = new Date().getTime(),
					result = encryptedString(key, LicenseKey),
					t2 = new Date().getTime();
			// txtMessages.value = "Done. Encryption took " + (t2 - t1) + " milliseconds.";
			return result;
		}

		function encryptForm() {
			var email = document.getElementById('email').value,
					txtDate = document.getElementById('expiry').value,
					productPrefix = document.getElementById('prefix').value,
					plainText = productPrefix + email + ':' + txtDate,
					encKey = document.getElementById('encryptionKey').value;
			if (!encKey) {
				alert('Please enter Encryption Key!');
				return;
			}
			alert( 'Encrypting License Key: ' + plainText);
			var license = plainText.replace('@','[at]') + ';' +  encrypt(plainText);
			document.getElementById('licenseKey').value = license;
			// store decryption key in cookie
			switch (key_type) {
				case 0:
					setCookie('simpleKey', encKey, 400); 
					break;
				case 1:
					setCookie('domainKey', encKey, 400); 
					break;
			}
		}

		function setCookie(cname, cvalue, exdays) {
			var d = new Date();
			d.setTime(d.getTime() + (exdays*24*60*60*1000));
			var expires = "expires="+ d.toUTCString();
			document.cookie = cname + "=" + cvalue + "; " + expires;
		}


		function getCookie(cname) {
			var name = cname + "=";
			var ca = document.cookie.split(';');
			for(var i = 0; i < ca.length; i++) {
				var c = ca[i];
				while (c.charAt(0) == ' ') {
						c = c.substring(1);
				}
				if (c.indexOf(name) == 0) {
						return c.substring(name.length, c.length);
				}
			}
			return "";
		}

		function checkCookies() {
			var sKey = getCookie(key_type == 0 ? 'simpleKey' : 'domainKey');
			if (sKey != "") {
				document.getElementById('encryptionKey').value = sKey;
			} 
		}
		</script>

		<p style="font-style: italic; border: 2px solid gray; padding: 0.7em; margin: 0.5em 0;">Disclaimer: this form uses a cookie to store the encryption key on your hard drive. 
			 If you use this page for encrypting a license key, you agree to the use of that cookie. 
		</p>
		<h3>Form Entry</h3>
		<form>
			<div class = "formContainer">
				<div class="formBox" id="personData">
					<span class="boxLabel">User Data</span><br>
					<span class="label">Prefix:</span> <input type="text" id="prefix"/><br>
					<span class="label" id="emailLabel">Email:</span> <input type="text" id="email"/><br>
					<span class="label">Expiry Date:</span> <input type="text" id="expiry"/>
					<div class="buttonPanel">
						<button type="button" id="btnEncrypt" onclick="encryptForm(); return false;">Encrypt!</button>
					</div>
				</div>
				<div class="encryptionBox formBox">
					<span class="boxLabel" id="infoLabel" onclick="toggleEncryption();">Encryption Info</span><br>
					<span class="label">Max Digits:</span><input type="text" id="maxDigits"/>
					<span class="label"  style="margin-left: 8em !important;">Key Size:</span><input type="text" id="keySize" />
					<br>
					<span class="label">Encryption Key:</span><input type="text" id="encryptionKey" />
					<br>
					<span class="label">Decryption Key:</span><input type="text" id="decryptionKey" />
					<br>
					<span class="label">Modulo:</span><input type="text" id="modulo" />
				</div>
			</div>
			<h4>License Key</h4>
			<p>
				<textarea id="licenseKey" rows="4" cols="65" wrap="hard"></textarea>
			</p>	
				

		</form>
		</div>

	<script type="text/javascript">
		onPageLoad();
	</script>
	

</body>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>