Implemented encrypting and decrypting of IOTA seeds

This commit is contained in:
Peter Ryszkiewicz 2017-09-03 13:40:53 -05:00
parent 115bd59424
commit b2dfa35317
11 changed files with 805 additions and 2 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.idea

View File

@ -1,2 +1,66 @@
# iota-seed-encryptor
Encrypts and decrypts your IOTA seed
# IOTA Seed Encryptor/Decryptor
Encrypts and decrypts your IOTA seeds.
[View the page hosted on GitHub Pages here.](https://prizz.github.io/iota-seed-encryptor-decryptor/)
# Secure Usage of this Webapp
This webapp does not store or transmit your data. But to be safe, in case of malware, or rogue browser extensions, follow these steps:
* [Download this webapp](https://github.com/pRizz/iota-seed-encryptor-decryptor/archive/master.zip) for offline use
* Disconnect from the internet
* Open this webapp (the index.html file) in incognito, or private browsing mode, with no extensions, or all extensions disabled
* Encrypt and Decrypt
* Quit your browser
# How does this work?
IOTA Seed Encryptor/Decryptor utilizes symmetric encryption from the [PGP protocol](https://en.wikipedia.org/wiki/Pretty_Good_Privacy). Your password acts as the symmetric key during the encryption and decryption process.
The PGP implementation used in this project comes from the open source project [OpenPGP.js](https://github.com/openpgpjs/openpgpjs)
# Encrypting and Decrypting on the Terminal
First, you must install a PGP client on your computer. GNU's implementation, [GPG](https://gnupg.org/download/index.html), is quite popular and available on most common platforms.
Here is how to encrypt files on the terminal
```
gpg --symmetric file.txt
```
You are then asked to enter the encryption passphrase.
Decrypting is similar; just pass the encrypted file to gpg
```
gpg file.txt.pgp
```
And enter in the passphrase
# Disclaimer
This project is not affiliated with the IOTA Foundation. You use this software at your own risk. I, Peter Ryszkiewicz, am not responsible for any misuse or abuse of this software. See the MIT License below for more details.
# About the Author
This project was originally created by Peter Ryszkiewicz [pRizz@Github](https://github.com/pRizz), software engineer in Chicago, IL. Beware of copycats.
# About the Project
This project is hosted on GitHub at [https://github.com/pRizz/iota-seed-encryptor-decryptor](https://github.com/pRizz/iota-seed-encryptor-decryptor) under the MIT license.
# License
```
MIT License
Copyright (c) 2017 Peter Ryszkiewicz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```

6
css/bootstrap.min.css vendored Normal file

File diff suppressed because one or more lines are too long

152
css/dragAndDrop.css Normal file
View File

@ -0,0 +1,152 @@
/* Base code from https://css-tricks.com/examples/DragAndDropFileUploading/?submit-on-demand */
.box
{
font-size: 2rem; /* 20 */
background-color: #ddd;
position: relative;
padding: 40px 10px 20px;
}
.box.has-advanced-upload
{
outline: 2px dashed #92b0b3;
outline-offset: -10px;
-webkit-transition: outline-offset .15s ease-in-out, background-color .15s linear;
transition: outline-offset .15s ease-in-out, background-color .15s linear;
}
.box.is-dragover
{
outline-offset: -20px;
outline-color: #c8dadf;
background-color: #fff;
}
.box__dragndrop,
.box__icon
{
display: none;
}
.box.has-advanced-upload .box__dragndrop
{
display: inline;
}
.box.has-advanced-upload .box__icon
{
width: 100%;
height: 80px;
fill: #92b0b3;
display: block;
margin-bottom: 25px;
}
.box.is-uploading .box__input,
.box.is-success .box__input,
.box.is-error .box__input
{
visibility: hidden;
}
.box.is-error
{
background-color: #ea1010;
}
.box__uploading,
.box__success,
.box__error
{
display: none;
}
.box.is-uploading .box__uploading,
.box.is-success .box__success,
.box.is-error .box__error
{
/*display: block;*/
/*position: absolute;*/
/*top: 50%;*/
/*right: 0;*/
/*left: 0;*/
/*-webkit-transform: translateY( -50% );*/
/*transform: translateY( -50% );*/
}
.box__uploading
{
font-style: italic;
}
.box__success
{
-webkit-animation: appear-from-inside .25s ease-in-out;
animation: appear-from-inside .25s ease-in-out;
}
@-webkit-keyframes appear-from-inside
{
from { -webkit-transform: translateY( -50% ) scale( 0 ); }
75% { -webkit-transform: translateY( -50% ) scale( 1.1 ); }
to { -webkit-transform: translateY( -50% ) scale( 1 ); }
}
@keyframes appear-from-inside
{
from { transform: translateY( -50% ) scale( 0 ); }
75% { transform: translateY( -50% ) scale( 1.1 ); }
to { transform: translateY( -50% ) scale( 1 ); }
}
.box__restart
{
font-weight: 700;
}
.box__restart:focus,
.box__restart:hover
{
color: #39bfd3;
}
.box__file
{
width: 0;
height: 0;
opacity: 0;
overflow: hidden;
position: absolute;
z-index: -1;
}
.box__file + label
{
max-width: 80%;
text-overflow: ellipsis;
white-space: nowrap;
cursor: pointer;
display: inline-block;
overflow: hidden;
}
.box__file + label:hover strong,
.box__file:focus + label strong,
.box__file.has-focus + label strong
{
color: #39bfd3;
}
.box__file:focus + label,
.box__file.has-focus + label
{
outline: -webkit-focus-ring-color auto 5px;
}
.box__file + label *
{
/* pointer-events: none; */ /* in case of FastClick lib use */
}
.box__button
{
font-weight: 700;
color: #e5edf1;
background-color: #39bfd3;
display: block;
padding: 8px 16px;
margin: 40px auto 0;
}
.box__button:hover,
.box__button:focus
{
background-color: #0f3c4b;
}

73
css/jumbotron-narrow.css Normal file
View File

@ -0,0 +1,73 @@
/* Space out content a bit */
body {
padding-top: 20px;
padding-bottom: 20px;
}
/* Everything but the jumbotron gets side spacing for mobile first views */
.header,
.marketing,
.footer {
padding-right: 15px;
padding-left: 15px;
}
/* Custom page header */
.header {
padding-bottom: 20px;
border-bottom: 1px solid #e5e5e5;
}
/* Make the masthead heading the same height as the navigation */
.header h3 {
margin-top: 0;
margin-bottom: 0;
line-height: 40px;
}
/* Custom page footer */
.footer {
padding-top: 19px;
color: #777;
border-top: 1px solid #e5e5e5;
}
.container-narrow > hr {
margin: 30px 0;
}
/* Main marketing message and sign up button */
.jumbotron {
text-align: center;
border-bottom: 1px solid #e5e5e5;
}
.jumbotron .btn {
padding: 14px 24px;
font-size: 21px;
}
/* Supporting marketing content */
.marketing {
margin: 40px 0;
}
.marketing p + h4 {
margin-top: 28px;
}
/* Responsive: Portrait tablets and up */
@media screen and (min-width: 768px) {
/* Remove the padding we set earlier */
.header,
.marketing,
.footer {
padding-right: 0;
padding-left: 0;
}
/* Space out the masthead */
.header {
margin-bottom: 30px;
}
/* Remove the bottom border on the jumbotron for visual effect */
.jumbotron {
border-bottom: 0;
}
}

256
index.html Normal file
View File

@ -0,0 +1,256 @@
<!DOCTYPE html>
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" type="image/x-icon" href="https://assets-cdn.github.com/favicon.ico">
<title>IOTA Seed Encryptor/Decryptor</title>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/openpgp.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<link href="./css/bootstrap.min.css" rel="stylesheet">
<link href="./css/jumbotron-narrow.css" rel="stylesheet">
<link href="./css/dragAndDrop.css" rel="stylesheet">
</head>
<body style="color: #4a4a4a">
<div class="container">
<div class="header clearfix">
<nav>
<ul class="nav nav-pills pull-right">
<li class="nav-item">
<a class="nav-link active" href="" onclick="window.location.reload(true)">Refresh</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/pRizz/iota-seed-encryptor-decryptor">Source</a>
</li>
</ul>
</nav>
<h3 class="text-muted">IOTA Seed Encryptor/Decryptor</h3>
</div>
<div class="row marketing">
<div class="col-md-6">
<div class="panel panel-primary" style="text-align: center">
<div class="panel-heading">
<h2><strong>Encrypt</strong> your seed(s)</h2>
</div>
<div class="panel-body">
<div class="form-group">
<h3>Paste your seed(s) here</h3>
<textarea class="form-control" id="dataToEncrypt" rows="3"></textarea>
</div>
<div class="form-group">
<h3>Encrypt with Password</h3>
<input type="password" class="form-control input-lg" id="dataToEncryptPassword" placeholder="Password">
</div>
<a id="encryptLink" role="button" class="btn btn-success btn-lg btn-block" onclick="encryptData()">
Encrypt
</a>
</div>
</div>
<div class="panel panel-primary" style="text-align: center">
<div class="panel-heading">
<h2><strong>Encrypt</strong> your seed file</h2>
</div>
<div class="panel-body">
<form id="fileToEncryptForm" novalidate class="box">
<div class="box__input">
<svg class="box__icon" xmlns="http://www.w3.org/2000/svg" width="50" height="43" viewBox="0 0 50 43"><path d="M48.4 26.5c-.9 0-1.7.7-1.7 1.7v11.6h-43.3v-11.6c0-.9-.7-1.7-1.7-1.7s-1.7.7-1.7 1.7v13.2c0 .9.7 1.7 1.7 1.7h46.7c.9 0 1.7-.7 1.7-1.7v-13.2c0-1-.7-1.7-1.7-1.7zm-24.5 6.1c.3.3.8.5 1.2.5.4 0 .9-.2 1.2-.5l10-11.6c.7-.7.7-1.7 0-2.4s-1.7-.7-2.4 0l-7.1 8.3v-25.3c0-.9-.7-1.7-1.7-1.7s-1.7.7-1.7 1.7v25.3l-7.1-8.3c-.7-.7-1.7-.7-2.4 0s-.7 1.7 0 2.4l10 11.6z"></path></svg>
<input type="file" name="files[]" id="file" class="box__file" data-multiple-caption="{count} files selected" multiple />
<label for="file"><strong>Choose a file</strong><span class="box__dragndrop"> or drag it here</span>.</label>
</div>
<div class="box__success">Done! <a href="https://css-tricks.com/examples/DragAndDropFileUploading//?" class="box__restart" role="button">Upload more?</a></div>
<div class="box__error">Error! <span></span>. <a href="https://css-tricks.com/examples/DragAndDropFileUploading//?" class="box__restart" role="button">Try again!</a></div>
</form>
<div class="form-group">
<h3>Encrypt with Password</h3>
<input type="password" class="form-control input-lg" id="fileToEncryptPassword" placeholder="Password">
</div>
<a id="fileEncyrptLink" role="button" class="btn btn-success btn-lg btn-block" onclick="encryptFileData()">
Encrypt
</a>
</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-primary" id="usdToMIOTAPanel" style="text-align: center">
<div class="panel-heading">
<h2><strong>Decrypt</strong> your seed(s)</h2>
</div>
<div class="panel-body">
<form id="fileToDecryptForm" novalidate class="box">
<div class="box__input">
<svg class="box__icon" xmlns="http://www.w3.org/2000/svg" width="50" height="43" viewBox="0 0 50 43"><path d="M48.4 26.5c-.9 0-1.7.7-1.7 1.7v11.6h-43.3v-11.6c0-.9-.7-1.7-1.7-1.7s-1.7.7-1.7 1.7v13.2c0 .9.7 1.7 1.7 1.7h46.7c.9 0 1.7-.7 1.7-1.7v-13.2c0-1-.7-1.7-1.7-1.7zm-24.5 6.1c.3.3.8.5 1.2.5.4 0 .9-.2 1.2-.5l10-11.6c.7-.7.7-1.7 0-2.4s-1.7-.7-2.4 0l-7.1 8.3v-25.3c0-.9-.7-1.7-1.7-1.7s-1.7.7-1.7 1.7v25.3l-7.1-8.3c-.7-.7-1.7-.7-2.4 0s-.7 1.7 0 2.4l10 11.6z"></path></svg>
<input type="file" name="files[]" id="fileToDecryptInput" class="box__file" data-multiple-caption="{count} files selected" multiple />
<label for="fileToDecryptInput"><strong>Choose a file</strong><span class="box__dragndrop"> or drag it here</span>.</label>
</div>
<div class="box__success">Done! <a href="https://css-tricks.com/examples/DragAndDropFileUploading//?" class="box__restart" role="button">Upload more?</a></div>
<div class="box__error">Error! <span></span>. <a href="https://css-tricks.com/examples/DragAndDropFileUploading//?" class="box__restart" role="button">Try again!</a></div>
</form>
<div class="form-group">
<h3>Decrypt with Password</h3>
<input type="password" class="form-control input-lg" id="fileToDecryptPassword" placeholder="Password">
</div>
<a id="fileDecryptLink" role="button" class="btn btn-success btn-lg btn-block" onclick="decryptFileData('download')">
⇩ Download Decrypted
</a>
<a id="fileViewDecryptedLink" role="button" class="btn btn-success btn-lg btn-block" onclick="decryptFileData('view')">
&#x1f50d; View Decrypted
</a>
</div>
</div>
<div class="panel panel-info" id="" style="text-align: center">
<div class="panel-heading">
<h2>Secure Usage of this Webapp</h2>
</div>
<div class="panel-body">
<div>
<h3>
This webapp does not store or transmit your data. But to be safe, in case of malware, or rogue browser extensions, follow these steps:
</h3>
<h3>
- <a href="https://github.com/pRizz/iota-seed-encryptor-decryptor/archive/master.zip">Download this webapp</a> for offline use
</h3>
<h3>
- Disconnect from the internet
</h3>
<h3>
- Open this webapp (the index.html file) in incognito, or private browsing mode, with no extensions, or all extensions disabled
</h3>
<h3>
- Encrypt and Decrypt
</h3>
<h3>
- Quit your browser
</h3>
</div>
</div>
</div>
</div>
</div>
<div class="row marketing text-center">
<div class="col-md-8 col-md-offset-2">
<h1>How does this work?</h1>
<h2>
IOTA Seed Encryptor/Decryptor utilizes symmetric encryption from the <a href="https://en.wikipedia.org/wiki/Pretty_Good_Privacy">PGP protocol</a>. Your password acts as the symmetric key during the encryption and decryption process.
</h2>
<h2>
The PGP implementation used in this project comes from the open source project <a href="https://github.com/openpgpjs/openpgpjs">OpenPGP.js</a>
</h2>
</div>
</div>
<div class="row marketing text-center">
<div class="col-md-8 col-md-offset-2">
<h1>Encrypting and Decrypting on the Terminal</h1>
<h2>First, you must install a PGP client on your computer. GNU's implementation, <a href="https://gnupg.org/download/index.html">GPG</a>, is quite popular and available on most common platforms.</h2>
<h2>Here is how to encrypt files on the terminal</h2>
<pre class="text-left">
$ gpg --symmetric file.txt</pre>
<h2>You are then asked to enter the encryption passphrase.</h2>
<h2>Decrypting is similar; just pass the encrypted file to gpg</h2>
<pre class="text-left">
$ gpg file.txt.pgp</pre>
<h2>And enter in the passphrase</h2>
</div>
</div>
<div class="row marketing text-center">
<div class="col-md-8 col-md-offset-2">
<h1>Disclaimer</h1>
<h2>
This project is not affiliated with the IOTA Foundation. You use this software at your own risk. I, Peter Ryszkiewicz, am not responsible for any misuse or abuse of this software. See the MIT License below for more details.
</h2>
</div>
</div>
<div class="row marketing text-center">
<div class="col-md-8 col-md-offset-2">
<h1>About the Author</h1>
<h2>
This project was originally created by Peter Ryszkiewicz (<a href="https://github.com/pRizz">pRizz@Github</a>), software engineer in Chicago, IL. Beware of copycats.
</h2>
</div>
</div>
<div class="row marketing text-center">
<div class="col-md-8 col-md-offset-2">
<h1>About the Project</h1>
<h2>
This project is hosted on GitHub at <a href="https://github.com/pRizz/iota-seed-encryptor-decryptor">https://github.com/pRizz/iota-seed-encryptor-decryptor</a> under the MIT license.
</h2>
</div>
</div>
<div class="row marketing text-center">
<div class="col-md-8 col-md-offset-2">
<pre>
MIT License
Copyright (c) 2017 Peter Ryszkiewicz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
</pre>
</div>
</div>
<footer class="footer">
<p><a href="https://github.com/pRizz/iota-seed-encryptor-decryptor">Fork this on GitHub!</a></p>
<p><a href="https://github.com/pRizz/iota-seed-encryptor-decryptor/archive/master.zip">Download this webapp</a> for offline use
</p>
<p>
If you found this useful, consider donating IOTA to:
</p>
<pre>ARDPDHLZPQZRDBPKTZBIK9OFKCJMGCHFQJTQEXL9KRIVSHNRGHJCEOCMRFXGJMQXDVGNFTTS9GUIOJXXW9RONFYJKW</pre>
<p>© Peter Ryszkiewicz 2017</p>
</footer>
<div class="modal fade" id="decryptedTextModal" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Decrypted Text</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<pre id="decryptedTextModalBody"></pre>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div> <!-- /container -->
</body>
<script src="js/dragAndDrop.js"></script>
</html>

7
js/bootstrap.min.js vendored Normal file

File diff suppressed because one or more lines are too long

71
js/dragAndDrop.js Normal file
View File

@ -0,0 +1,71 @@
// Base code from https://css-tricks.com/examples/DragAndDropFileUploading/?submit-on-demand
'use strict';
;( function( $, window, document, undefined )
{
// feature detection for drag&drop upload
var isAdvancedUpload = function()
{
var div = document.createElement( 'div' );
return ( ( 'draggable' in div ) || ( 'ondragstart' in div && 'ondrop' in div ) ) && 'FormData' in window && 'FileReader' in window;
}();
// applying the effect for every form
$( '.box' ).each( function()
{
var $form = $( this ),
$input = $form.find( 'input[type="file"]' ),
$label = $form.find( 'label' ),
$errorMsg = $form.find( '.box__error span' ),
$restart = $form.find( '.box__restart' ),
droppedFiles = false,
showFiles = function( files )
{
$label.text( files.length > 1 ? ( $input.attr( 'data-multiple-caption' ) || '' ).replace( '{count}', files.length ) : files[ 0 ].name );
};
$input.on( 'change', function( e )
{
showFiles( e.target.files );
});
// drag&drop files if the feature is available
if( isAdvancedUpload )
{
$form
.addClass( 'has-advanced-upload' ) // letting the CSS part to know drag&drop is supported by the browser
.on( 'drag dragstart dragend dragover dragenter dragleave drop', function( e )
{
// preventing the unwanted behaviours
e.preventDefault();
e.stopPropagation();
})
.on( 'dragover dragenter', function() //
{
$form.addClass( 'is-dragover' );
})
.on( 'dragleave dragend drop', function()
{
$form.removeClass( 'is-dragover' );
})
.on( 'drop', function( e )
{
droppedFiles = e.originalEvent.dataTransfer.files; // the files that were dropped
showFiles( droppedFiles );
});
}
// Firefox focus bug fix for file input
$input
.on( 'focus', function(){ $input.addClass( 'has-focus' ); })
.on( 'blur', function(){ $input.removeClass( 'has-focus' ); });
});
})( jQuery, window, document );

4
js/jquery.min.js vendored Normal file

File diff suppressed because one or more lines are too long

159
js/main.js Normal file
View File

@ -0,0 +1,159 @@
/**
* Created by Peter Ryszkiewicz on 8/10/2017.
* https://github.com/pRizz/iota-seed-encryptor-decryptor
*/
var $dataToEncrypt
var $dataToEncryptPassword
var fileToEncrypt
var $fileToEncryptForm
var $fileToEncryptPassword
var generatedEncryptedFile
var fileToDecrypt
var $fileToDecryptForm
var $fileToDecryptPassword
var generatedDecryptedFile
function encryptData() {
if (!$dataToEncrypt[0].value) {
$dataToEncrypt.parent().addClass("has-error")
return
}
$dataToEncrypt.parent().removeClass('has-error')
if ($dataToEncryptPassword[0].value == "") {
$dataToEncryptPassword.parent().addClass('has-error')
return
}
$dataToEncryptPassword.parent().removeClass('has-error')
var encryptionOptions = {
data: $dataToEncrypt[0].value,
passwords: [$dataToEncryptPassword[0].value],
armor: false
};
openpgp.encrypt(encryptionOptions).then(function(ciphertext) {
const encrypted = ciphertext.message.packets.write(); // get raw encrypted packets as Uint8Array
const encryptedData = new Blob([encrypted], {type: "application/pgp-encrypted"})
generatedEncryptedFile = window.URL.createObjectURL(encryptedData)
const currentDateString = new Date().toISOString()
const downloadLink = $('<a></a>', {
href: generatedEncryptedFile,
download: `iotaSeeds-${currentDateString}.pgp`
}).appendTo('body')
downloadLink[0].click()
downloadLink.remove()
});
}
function encryptFileData() {
if (!fileToEncrypt) {
$fileToEncryptForm.addClass("is-error")
setTimeout(() => $fileToEncryptForm.removeClass("is-error"), 250)
return
}
if ($fileToEncryptPassword[0].value == "") {
$fileToEncryptPassword.parent().addClass('has-error')
return
}
$fileToEncryptPassword.parent().removeClass('has-error')
const fileReader = new FileReader()
fileReader.onload = function(e) {
const fileString = e.target.result
var encryptionOptions = {
data: fileString, // input as Uint8Array (or String)
passwords: [$fileToEncryptPassword[0].value], // multiple passwords possible
armor: false // don't ASCII armor (for Uint8Array output)
};
openpgp.encrypt(encryptionOptions).then(function(ciphertext) {
const encrypted = ciphertext.message.packets.write(); // get raw encrypted packets as Uint8Array
const encryptedData = new Blob([encrypted], {type: "application/pgp-encrypted"})
generatedEncryptedFile = window.URL.createObjectURL(encryptedData)
const currentDateString = new Date().toISOString()
const downloadLink = $('<a></a>', {
href: generatedEncryptedFile,
download: `iotaSeeds-${currentDateString}.pgp`
}).appendTo('body')
downloadLink[0].click()
downloadLink.remove()
});
};
fileReader.readAsText(fileToEncrypt)
}
function decryptFileData(action) {
if (!fileToDecrypt) {
$fileToDecryptForm.addClass("is-error")
setTimeout(() => $fileToDecryptForm.removeClass("is-error"), 250)
return
}
if ($fileToDecryptPassword[0].value == "") {
$fileToDecryptPassword.parent().addClass('has-error')
return
}
$fileToDecryptPassword.parent().removeClass('has-error')
const fileReader = new FileReader()
fileReader.onload = function(e) {
const encryptedUInt8Array = new Uint8Array(e.target.result)
var decryptionOptions = {
message: openpgp.message.read(encryptedUInt8Array),
password: $fileToDecryptPassword[0].value,
format: 'binary'
};
openpgp.decrypt(decryptionOptions).then(function(plaintext) {
if(action == 'download') {
const decryptedData = new Blob([plaintext.data], {type: "text/plain"})
generatedDecryptedFile = window.URL.createObjectURL(decryptedData)
const currentDateString = new Date().toISOString()
const downloadLink = $('<a></a>', {
href: generatedDecryptedFile,
download: `iotaSeeds-${currentDateString}.txt`
}).appendTo('body')
downloadLink[0].click()
downloadLink.remove()
} else if (action == 'view') {
$('#decryptedTextModalBody')[0].innerText = new TextDecoder('utf-8').decode(plaintext.data)
$('#decryptedTextModal').modal('show')
}
}).catch(function(error) {
alert(`Incorrect password or bad pgp file.\nError message: ${error}`)
})
};
fileReader.readAsArrayBuffer(fileToDecrypt)
}
$(function(){
$dataToEncrypt = $('#dataToEncrypt')
$dataToEncryptPassword = $('#dataToEncryptPassword')
$fileToEncryptForm = $("#fileToEncryptForm")
$fileToEncryptPassword = $("#fileToEncryptPassword")
$fileToEncryptForm.on('drop', function(e) {
const droppedFiles = e.originalEvent.dataTransfer.files
fileToEncrypt = droppedFiles[0]
})
$fileToDecryptForm = $("#fileToDecryptForm")
$fileToDecryptPassword = $("#fileToDecryptPassword")
$fileToDecryptForm.on('drop', function(e) {
const droppedFiles = e.originalEvent.dataTransfer.files
fileToDecrypt = droppedFiles[0]
})
})

10
js/openpgp.min.js vendored Normal file

File diff suppressed because one or more lines are too long