How to encrypt string using openpgp.js?
I am trying to use the Encrypt and decrypt String data with PGP keys example from openpgp.js but I struggle to make it work inside Firefox. openpgp.js doc
I create a keypair.
const openpgp = window.openpgp; // use as CommonJS, AMD, ES6 module or via window.openpgp
openpgp.config.compression = openpgp.enums.compression.zlib
var options = {
userIds: [{ name: 'Alicee', email: 'alice@example.com' }],
numBits: 2048,
passphrase: 'secretttoo'
};
var publicKeyAlice;
var privateKeyAlice;
openpgp.generateKey(options).then(key => {
privateKeyAlice = key.privateKeyArmored;
publicKeyAlice = key.publicKeyArmored;
console.log('Key generated');
console.log(privateKeyAlice);
console.log(publicKeyAlice);
});
The keys I get consoled out are used for the example of string encryption by openpgp.js
const pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK----- Version: OpenPGP.js v4.1.1'
const privkey = '-----BEGIN PGP PRIVATE KEY BLOCK----- Version: OpenPGP.js v4.1.1'
const passphrase = `secretttoo` //what the privKey is encrypted with
const encryptDecryptFunction = async() => {
const privKeyObj = (await openpgp.key.readArmored(privkey)).keys[0]
await privKeyObj.decrypt(passphrase)
const options = {
message: openpgp.message.fromText('Hello, World!'), // input as Message object
publicKeys: (await openpgp.key.readArmored(pubkey)).keys, // for encryption
privateKeys: [privKeyObj] // for signing (optional)
}
openpgp.encrypt(options).then(ciphertext => {
encrypted = ciphertext.data // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
return encrypted
})
.then(encrypted => {
const options = {
message: await openpgp.message.readArmored(encrypted), // parse armored message
publicKeys: (await openpgp.key.readArmored(pubkey)).keys, // for verification (optional)
privateKeys: [privKeyObj] // for decryption
}
openpgp.decrypt(options).then(plaintext => {
console.log(plaintext.data)
return plaintext.data // 'Hello, World!'
})
})
}
encryptDecryptFunction();
I get the following error in browser console:
SyntaxError: missing } after property list[Learn More] openpgp testing.html:153:27 note: { opened at line 152, column 24
How does a simple pgp encryption of string work using openpgp.js?
javascript encryption public-key-encryption openpgp.js
add a comment |
I am trying to use the Encrypt and decrypt String data with PGP keys example from openpgp.js but I struggle to make it work inside Firefox. openpgp.js doc
I create a keypair.
const openpgp = window.openpgp; // use as CommonJS, AMD, ES6 module or via window.openpgp
openpgp.config.compression = openpgp.enums.compression.zlib
var options = {
userIds: [{ name: 'Alicee', email: 'alice@example.com' }],
numBits: 2048,
passphrase: 'secretttoo'
};
var publicKeyAlice;
var privateKeyAlice;
openpgp.generateKey(options).then(key => {
privateKeyAlice = key.privateKeyArmored;
publicKeyAlice = key.publicKeyArmored;
console.log('Key generated');
console.log(privateKeyAlice);
console.log(publicKeyAlice);
});
The keys I get consoled out are used for the example of string encryption by openpgp.js
const pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK----- Version: OpenPGP.js v4.1.1'
const privkey = '-----BEGIN PGP PRIVATE KEY BLOCK----- Version: OpenPGP.js v4.1.1'
const passphrase = `secretttoo` //what the privKey is encrypted with
const encryptDecryptFunction = async() => {
const privKeyObj = (await openpgp.key.readArmored(privkey)).keys[0]
await privKeyObj.decrypt(passphrase)
const options = {
message: openpgp.message.fromText('Hello, World!'), // input as Message object
publicKeys: (await openpgp.key.readArmored(pubkey)).keys, // for encryption
privateKeys: [privKeyObj] // for signing (optional)
}
openpgp.encrypt(options).then(ciphertext => {
encrypted = ciphertext.data // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
return encrypted
})
.then(encrypted => {
const options = {
message: await openpgp.message.readArmored(encrypted), // parse armored message
publicKeys: (await openpgp.key.readArmored(pubkey)).keys, // for verification (optional)
privateKeys: [privKeyObj] // for decryption
}
openpgp.decrypt(options).then(plaintext => {
console.log(plaintext.data)
return plaintext.data // 'Hello, World!'
})
})
}
encryptDecryptFunction();
I get the following error in browser console:
SyntaxError: missing } after property list[Learn More] openpgp testing.html:153:27 note: { opened at line 152, column 24
How does a simple pgp encryption of string work using openpgp.js?
javascript encryption public-key-encryption openpgp.js
add a comment |
I am trying to use the Encrypt and decrypt String data with PGP keys example from openpgp.js but I struggle to make it work inside Firefox. openpgp.js doc
I create a keypair.
const openpgp = window.openpgp; // use as CommonJS, AMD, ES6 module or via window.openpgp
openpgp.config.compression = openpgp.enums.compression.zlib
var options = {
userIds: [{ name: 'Alicee', email: 'alice@example.com' }],
numBits: 2048,
passphrase: 'secretttoo'
};
var publicKeyAlice;
var privateKeyAlice;
openpgp.generateKey(options).then(key => {
privateKeyAlice = key.privateKeyArmored;
publicKeyAlice = key.publicKeyArmored;
console.log('Key generated');
console.log(privateKeyAlice);
console.log(publicKeyAlice);
});
The keys I get consoled out are used for the example of string encryption by openpgp.js
const pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK----- Version: OpenPGP.js v4.1.1'
const privkey = '-----BEGIN PGP PRIVATE KEY BLOCK----- Version: OpenPGP.js v4.1.1'
const passphrase = `secretttoo` //what the privKey is encrypted with
const encryptDecryptFunction = async() => {
const privKeyObj = (await openpgp.key.readArmored(privkey)).keys[0]
await privKeyObj.decrypt(passphrase)
const options = {
message: openpgp.message.fromText('Hello, World!'), // input as Message object
publicKeys: (await openpgp.key.readArmored(pubkey)).keys, // for encryption
privateKeys: [privKeyObj] // for signing (optional)
}
openpgp.encrypt(options).then(ciphertext => {
encrypted = ciphertext.data // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
return encrypted
})
.then(encrypted => {
const options = {
message: await openpgp.message.readArmored(encrypted), // parse armored message
publicKeys: (await openpgp.key.readArmored(pubkey)).keys, // for verification (optional)
privateKeys: [privKeyObj] // for decryption
}
openpgp.decrypt(options).then(plaintext => {
console.log(plaintext.data)
return plaintext.data // 'Hello, World!'
})
})
}
encryptDecryptFunction();
I get the following error in browser console:
SyntaxError: missing } after property list[Learn More] openpgp testing.html:153:27 note: { opened at line 152, column 24
How does a simple pgp encryption of string work using openpgp.js?
javascript encryption public-key-encryption openpgp.js
I am trying to use the Encrypt and decrypt String data with PGP keys example from openpgp.js but I struggle to make it work inside Firefox. openpgp.js doc
I create a keypair.
const openpgp = window.openpgp; // use as CommonJS, AMD, ES6 module or via window.openpgp
openpgp.config.compression = openpgp.enums.compression.zlib
var options = {
userIds: [{ name: 'Alicee', email: 'alice@example.com' }],
numBits: 2048,
passphrase: 'secretttoo'
};
var publicKeyAlice;
var privateKeyAlice;
openpgp.generateKey(options).then(key => {
privateKeyAlice = key.privateKeyArmored;
publicKeyAlice = key.publicKeyArmored;
console.log('Key generated');
console.log(privateKeyAlice);
console.log(publicKeyAlice);
});
The keys I get consoled out are used for the example of string encryption by openpgp.js
const pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK----- Version: OpenPGP.js v4.1.1'
const privkey = '-----BEGIN PGP PRIVATE KEY BLOCK----- Version: OpenPGP.js v4.1.1'
const passphrase = `secretttoo` //what the privKey is encrypted with
const encryptDecryptFunction = async() => {
const privKeyObj = (await openpgp.key.readArmored(privkey)).keys[0]
await privKeyObj.decrypt(passphrase)
const options = {
message: openpgp.message.fromText('Hello, World!'), // input as Message object
publicKeys: (await openpgp.key.readArmored(pubkey)).keys, // for encryption
privateKeys: [privKeyObj] // for signing (optional)
}
openpgp.encrypt(options).then(ciphertext => {
encrypted = ciphertext.data // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
return encrypted
})
.then(encrypted => {
const options = {
message: await openpgp.message.readArmored(encrypted), // parse armored message
publicKeys: (await openpgp.key.readArmored(pubkey)).keys, // for verification (optional)
privateKeys: [privKeyObj] // for decryption
}
openpgp.decrypt(options).then(plaintext => {
console.log(plaintext.data)
return plaintext.data // 'Hello, World!'
})
})
}
encryptDecryptFunction();
I get the following error in browser console:
SyntaxError: missing } after property list[Learn More] openpgp testing.html:153:27 note: { opened at line 152, column 24
How does a simple pgp encryption of string work using openpgp.js?
javascript encryption public-key-encryption openpgp.js
javascript encryption public-key-encryption openpgp.js
asked Nov 25 '18 at 13:08
codebird456codebird456
687
687
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
To actually answer your question over suggesting another library, the fix is in changeing the syntax from
message: await openpgp.message.readArmored(encrypted),
to
message: openpgp.message.readArmored(encrypted),
Then it should works since that method is not async (anymore?)
Here your example modified for symetric encryption (that's why I couldn't use jsencrypt as Nikola suggested:
<script lang="JavaScript" src="openpgp.js"></script>
<script lang="JavaScript">
const options = {
message : window.openpgp.message.fromText('Hello, World!'),
passwords : ['pw'],
armor : false
}
window.openpgp.encrypt(options).then(ciphertext => {
encrypted = ciphertext.message
return encrypted
}).then(encrypted => {
const options = {
message : encrypted,
passwords : ['pw']
}
window.openpgp.decrypt(options).then(plaintext => {
console.log(plaintext.data)
alert(plaintext.data)
return plaintext.data
})
})
</script>
add a comment |
The library you're trying to use doesn't look that promissing for asymetric cryptography.
If you're open for suggestion try using this one.
Here is example code :
<div class="container">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsencrypt/2.3.1/jsencrypt.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script type="text/javascript">
// Call this code when the page is done loading.
jQuery(function () {
// Run a quick encryption/decryption when they click.
jQuery('#testme').click(function () {
// Encrypt with the public key...
var encrypt = new JSEncrypt();
encrypt.setPublicKey($('#pubkey').val());
var encrypted = encrypt.encrypt($('#input').val());
console.log(encrypted);
// Decrypt with the private key...
var decrypt = new JSEncrypt();
decrypt.setPrivateKey($('#privkey').val());
var uncrypted = decrypt.decrypt(encrypted);
// Now a simple check to see if the round-trip worked.
if (uncrypted == $('#input').val()) {
alert('It works!!!');
}
else {
alert('Something went wrong....');
}
});
});
</script>
<label for="privkey">Private Key</label><br/>
<textarea id="privkey" rows="15" cols="65">-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDlOJu6TyygqxfWT7eLtGDwajtNFOb9I5XRb6khyfD1Yt3YiCgQ
WMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76xFxdU6jE0NQ+Z+zEdhUTooNR
aY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4gwQco1KRMDSmXSMkDwIDAQAB
AoGAfY9LpnuWK5Bs50UVep5c93SJdUi82u7yMx4iHFMc/Z2hfenfYEzu+57fI4fv
xTQ//5DbzRR/XKb8ulNv6+CHyPF31xk7YOBfkGI8qjLoq06V+FyBfDSwL8KbLyeH
m7KUZnLNQbk8yGLzB3iYKkRHlmUanQGaNMIJziWOkN+N9dECQQD0ONYRNZeuM8zd
8XJTSdcIX4a3gy3GGCJxOzv16XHxD03GW6UNLmfPwenKu+cdrQeaqEixrCejXdAF
z/7+BSMpAkEA8EaSOeP5Xr3ZrbiKzi6TGMwHMvC7HdJxaBJbVRfApFrE0/mPwmP5
rN7QwjrMY+0+AbXcm8mRQyQ1+IGEembsdwJBAN6az8Rv7QnD/YBvi52POIlRSSIM
V7SwWvSK4WSMnGb1ZBbhgdg57DXaspcwHsFV7hByQ5BvMtIduHcT14ECfcECQATe
aTgjFnqE/lQ22Rk0eGaYO80cc643BXVGafNfd9fcvwBMnk0iGX0XRsOozVt5Azil
psLBYuApa66NcVHJpCECQQDTjI2AQhFc1yRnCU/YgDnSpJVm1nASoRUnU8Jfm3Oz
uku7JUXcVpt08DFSceCEX9unCuMcT72rAQlLpdZir876
-----END RSA PRIVATE KEY-----</textarea><br/>
<label for="pubkey">Public Key</label><br/>
<textarea id="pubkey" rows="15" cols="65">-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDlOJu6TyygqxfWT7eLtGDwajtN
FOb9I5XRb6khyfD1Yt3YiCgQWMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76
xFxdU6jE0NQ+Z+zEdhUTooNRaY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4
gwQco1KRMDSmXSMkDwIDAQAB
-----END PUBLIC KEY-----</textarea><br/>
<label for="input">Text to encrypt:</label><br/>
<textarea id="input" name="input" type="text" rows=4 cols=70>This is a test!</textarea><br/>
<input id="testme" type="button" value="Test Me!!!"/><br/>
</div>
Thanks for your suggestion. I am open to other libs as its just for my training. Do you the methods of this lib to create the keypairs inside the browser instead of using openssl genrsa -out rsa_1024_priv.pem 1024 ?
– codebird456
Nov 25 '18 at 14:50
1
Maybe this will help. juhoen.github.io/hybrid-crypto-js
– Nikola Pavlović
Nov 25 '18 at 14:53
this one works well. Fast and easy to play around. Thnaks
– codebird456
Nov 25 '18 at 18:08
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467770%2fhow-to-encrypt-string-using-openpgp-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
To actually answer your question over suggesting another library, the fix is in changeing the syntax from
message: await openpgp.message.readArmored(encrypted),
to
message: openpgp.message.readArmored(encrypted),
Then it should works since that method is not async (anymore?)
Here your example modified for symetric encryption (that's why I couldn't use jsencrypt as Nikola suggested:
<script lang="JavaScript" src="openpgp.js"></script>
<script lang="JavaScript">
const options = {
message : window.openpgp.message.fromText('Hello, World!'),
passwords : ['pw'],
armor : false
}
window.openpgp.encrypt(options).then(ciphertext => {
encrypted = ciphertext.message
return encrypted
}).then(encrypted => {
const options = {
message : encrypted,
passwords : ['pw']
}
window.openpgp.decrypt(options).then(plaintext => {
console.log(plaintext.data)
alert(plaintext.data)
return plaintext.data
})
})
</script>
add a comment |
To actually answer your question over suggesting another library, the fix is in changeing the syntax from
message: await openpgp.message.readArmored(encrypted),
to
message: openpgp.message.readArmored(encrypted),
Then it should works since that method is not async (anymore?)
Here your example modified for symetric encryption (that's why I couldn't use jsencrypt as Nikola suggested:
<script lang="JavaScript" src="openpgp.js"></script>
<script lang="JavaScript">
const options = {
message : window.openpgp.message.fromText('Hello, World!'),
passwords : ['pw'],
armor : false
}
window.openpgp.encrypt(options).then(ciphertext => {
encrypted = ciphertext.message
return encrypted
}).then(encrypted => {
const options = {
message : encrypted,
passwords : ['pw']
}
window.openpgp.decrypt(options).then(plaintext => {
console.log(plaintext.data)
alert(plaintext.data)
return plaintext.data
})
})
</script>
add a comment |
To actually answer your question over suggesting another library, the fix is in changeing the syntax from
message: await openpgp.message.readArmored(encrypted),
to
message: openpgp.message.readArmored(encrypted),
Then it should works since that method is not async (anymore?)
Here your example modified for symetric encryption (that's why I couldn't use jsencrypt as Nikola suggested:
<script lang="JavaScript" src="openpgp.js"></script>
<script lang="JavaScript">
const options = {
message : window.openpgp.message.fromText('Hello, World!'),
passwords : ['pw'],
armor : false
}
window.openpgp.encrypt(options).then(ciphertext => {
encrypted = ciphertext.message
return encrypted
}).then(encrypted => {
const options = {
message : encrypted,
passwords : ['pw']
}
window.openpgp.decrypt(options).then(plaintext => {
console.log(plaintext.data)
alert(plaintext.data)
return plaintext.data
})
})
</script>
To actually answer your question over suggesting another library, the fix is in changeing the syntax from
message: await openpgp.message.readArmored(encrypted),
to
message: openpgp.message.readArmored(encrypted),
Then it should works since that method is not async (anymore?)
Here your example modified for symetric encryption (that's why I couldn't use jsencrypt as Nikola suggested:
<script lang="JavaScript" src="openpgp.js"></script>
<script lang="JavaScript">
const options = {
message : window.openpgp.message.fromText('Hello, World!'),
passwords : ['pw'],
armor : false
}
window.openpgp.encrypt(options).then(ciphertext => {
encrypted = ciphertext.message
return encrypted
}).then(encrypted => {
const options = {
message : encrypted,
passwords : ['pw']
}
window.openpgp.decrypt(options).then(plaintext => {
console.log(plaintext.data)
alert(plaintext.data)
return plaintext.data
})
})
</script>
edited Jan 6 at 0:28
answered Jan 6 at 0:12
Romeo KienzlerRomeo Kienzler
1,4351434
1,4351434
add a comment |
add a comment |
The library you're trying to use doesn't look that promissing for asymetric cryptography.
If you're open for suggestion try using this one.
Here is example code :
<div class="container">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsencrypt/2.3.1/jsencrypt.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script type="text/javascript">
// Call this code when the page is done loading.
jQuery(function () {
// Run a quick encryption/decryption when they click.
jQuery('#testme').click(function () {
// Encrypt with the public key...
var encrypt = new JSEncrypt();
encrypt.setPublicKey($('#pubkey').val());
var encrypted = encrypt.encrypt($('#input').val());
console.log(encrypted);
// Decrypt with the private key...
var decrypt = new JSEncrypt();
decrypt.setPrivateKey($('#privkey').val());
var uncrypted = decrypt.decrypt(encrypted);
// Now a simple check to see if the round-trip worked.
if (uncrypted == $('#input').val()) {
alert('It works!!!');
}
else {
alert('Something went wrong....');
}
});
});
</script>
<label for="privkey">Private Key</label><br/>
<textarea id="privkey" rows="15" cols="65">-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDlOJu6TyygqxfWT7eLtGDwajtNFOb9I5XRb6khyfD1Yt3YiCgQ
WMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76xFxdU6jE0NQ+Z+zEdhUTooNR
aY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4gwQco1KRMDSmXSMkDwIDAQAB
AoGAfY9LpnuWK5Bs50UVep5c93SJdUi82u7yMx4iHFMc/Z2hfenfYEzu+57fI4fv
xTQ//5DbzRR/XKb8ulNv6+CHyPF31xk7YOBfkGI8qjLoq06V+FyBfDSwL8KbLyeH
m7KUZnLNQbk8yGLzB3iYKkRHlmUanQGaNMIJziWOkN+N9dECQQD0ONYRNZeuM8zd
8XJTSdcIX4a3gy3GGCJxOzv16XHxD03GW6UNLmfPwenKu+cdrQeaqEixrCejXdAF
z/7+BSMpAkEA8EaSOeP5Xr3ZrbiKzi6TGMwHMvC7HdJxaBJbVRfApFrE0/mPwmP5
rN7QwjrMY+0+AbXcm8mRQyQ1+IGEembsdwJBAN6az8Rv7QnD/YBvi52POIlRSSIM
V7SwWvSK4WSMnGb1ZBbhgdg57DXaspcwHsFV7hByQ5BvMtIduHcT14ECfcECQATe
aTgjFnqE/lQ22Rk0eGaYO80cc643BXVGafNfd9fcvwBMnk0iGX0XRsOozVt5Azil
psLBYuApa66NcVHJpCECQQDTjI2AQhFc1yRnCU/YgDnSpJVm1nASoRUnU8Jfm3Oz
uku7JUXcVpt08DFSceCEX9unCuMcT72rAQlLpdZir876
-----END RSA PRIVATE KEY-----</textarea><br/>
<label for="pubkey">Public Key</label><br/>
<textarea id="pubkey" rows="15" cols="65">-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDlOJu6TyygqxfWT7eLtGDwajtN
FOb9I5XRb6khyfD1Yt3YiCgQWMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76
xFxdU6jE0NQ+Z+zEdhUTooNRaY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4
gwQco1KRMDSmXSMkDwIDAQAB
-----END PUBLIC KEY-----</textarea><br/>
<label for="input">Text to encrypt:</label><br/>
<textarea id="input" name="input" type="text" rows=4 cols=70>This is a test!</textarea><br/>
<input id="testme" type="button" value="Test Me!!!"/><br/>
</div>
Thanks for your suggestion. I am open to other libs as its just for my training. Do you the methods of this lib to create the keypairs inside the browser instead of using openssl genrsa -out rsa_1024_priv.pem 1024 ?
– codebird456
Nov 25 '18 at 14:50
1
Maybe this will help. juhoen.github.io/hybrid-crypto-js
– Nikola Pavlović
Nov 25 '18 at 14:53
this one works well. Fast and easy to play around. Thnaks
– codebird456
Nov 25 '18 at 18:08
add a comment |
The library you're trying to use doesn't look that promissing for asymetric cryptography.
If you're open for suggestion try using this one.
Here is example code :
<div class="container">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsencrypt/2.3.1/jsencrypt.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script type="text/javascript">
// Call this code when the page is done loading.
jQuery(function () {
// Run a quick encryption/decryption when they click.
jQuery('#testme').click(function () {
// Encrypt with the public key...
var encrypt = new JSEncrypt();
encrypt.setPublicKey($('#pubkey').val());
var encrypted = encrypt.encrypt($('#input').val());
console.log(encrypted);
// Decrypt with the private key...
var decrypt = new JSEncrypt();
decrypt.setPrivateKey($('#privkey').val());
var uncrypted = decrypt.decrypt(encrypted);
// Now a simple check to see if the round-trip worked.
if (uncrypted == $('#input').val()) {
alert('It works!!!');
}
else {
alert('Something went wrong....');
}
});
});
</script>
<label for="privkey">Private Key</label><br/>
<textarea id="privkey" rows="15" cols="65">-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDlOJu6TyygqxfWT7eLtGDwajtNFOb9I5XRb6khyfD1Yt3YiCgQ
WMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76xFxdU6jE0NQ+Z+zEdhUTooNR
aY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4gwQco1KRMDSmXSMkDwIDAQAB
AoGAfY9LpnuWK5Bs50UVep5c93SJdUi82u7yMx4iHFMc/Z2hfenfYEzu+57fI4fv
xTQ//5DbzRR/XKb8ulNv6+CHyPF31xk7YOBfkGI8qjLoq06V+FyBfDSwL8KbLyeH
m7KUZnLNQbk8yGLzB3iYKkRHlmUanQGaNMIJziWOkN+N9dECQQD0ONYRNZeuM8zd
8XJTSdcIX4a3gy3GGCJxOzv16XHxD03GW6UNLmfPwenKu+cdrQeaqEixrCejXdAF
z/7+BSMpAkEA8EaSOeP5Xr3ZrbiKzi6TGMwHMvC7HdJxaBJbVRfApFrE0/mPwmP5
rN7QwjrMY+0+AbXcm8mRQyQ1+IGEembsdwJBAN6az8Rv7QnD/YBvi52POIlRSSIM
V7SwWvSK4WSMnGb1ZBbhgdg57DXaspcwHsFV7hByQ5BvMtIduHcT14ECfcECQATe
aTgjFnqE/lQ22Rk0eGaYO80cc643BXVGafNfd9fcvwBMnk0iGX0XRsOozVt5Azil
psLBYuApa66NcVHJpCECQQDTjI2AQhFc1yRnCU/YgDnSpJVm1nASoRUnU8Jfm3Oz
uku7JUXcVpt08DFSceCEX9unCuMcT72rAQlLpdZir876
-----END RSA PRIVATE KEY-----</textarea><br/>
<label for="pubkey">Public Key</label><br/>
<textarea id="pubkey" rows="15" cols="65">-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDlOJu6TyygqxfWT7eLtGDwajtN
FOb9I5XRb6khyfD1Yt3YiCgQWMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76
xFxdU6jE0NQ+Z+zEdhUTooNRaY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4
gwQco1KRMDSmXSMkDwIDAQAB
-----END PUBLIC KEY-----</textarea><br/>
<label for="input">Text to encrypt:</label><br/>
<textarea id="input" name="input" type="text" rows=4 cols=70>This is a test!</textarea><br/>
<input id="testme" type="button" value="Test Me!!!"/><br/>
</div>
Thanks for your suggestion. I am open to other libs as its just for my training. Do you the methods of this lib to create the keypairs inside the browser instead of using openssl genrsa -out rsa_1024_priv.pem 1024 ?
– codebird456
Nov 25 '18 at 14:50
1
Maybe this will help. juhoen.github.io/hybrid-crypto-js
– Nikola Pavlović
Nov 25 '18 at 14:53
this one works well. Fast and easy to play around. Thnaks
– codebird456
Nov 25 '18 at 18:08
add a comment |
The library you're trying to use doesn't look that promissing for asymetric cryptography.
If you're open for suggestion try using this one.
Here is example code :
<div class="container">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsencrypt/2.3.1/jsencrypt.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script type="text/javascript">
// Call this code when the page is done loading.
jQuery(function () {
// Run a quick encryption/decryption when they click.
jQuery('#testme').click(function () {
// Encrypt with the public key...
var encrypt = new JSEncrypt();
encrypt.setPublicKey($('#pubkey').val());
var encrypted = encrypt.encrypt($('#input').val());
console.log(encrypted);
// Decrypt with the private key...
var decrypt = new JSEncrypt();
decrypt.setPrivateKey($('#privkey').val());
var uncrypted = decrypt.decrypt(encrypted);
// Now a simple check to see if the round-trip worked.
if (uncrypted == $('#input').val()) {
alert('It works!!!');
}
else {
alert('Something went wrong....');
}
});
});
</script>
<label for="privkey">Private Key</label><br/>
<textarea id="privkey" rows="15" cols="65">-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDlOJu6TyygqxfWT7eLtGDwajtNFOb9I5XRb6khyfD1Yt3YiCgQ
WMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76xFxdU6jE0NQ+Z+zEdhUTooNR
aY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4gwQco1KRMDSmXSMkDwIDAQAB
AoGAfY9LpnuWK5Bs50UVep5c93SJdUi82u7yMx4iHFMc/Z2hfenfYEzu+57fI4fv
xTQ//5DbzRR/XKb8ulNv6+CHyPF31xk7YOBfkGI8qjLoq06V+FyBfDSwL8KbLyeH
m7KUZnLNQbk8yGLzB3iYKkRHlmUanQGaNMIJziWOkN+N9dECQQD0ONYRNZeuM8zd
8XJTSdcIX4a3gy3GGCJxOzv16XHxD03GW6UNLmfPwenKu+cdrQeaqEixrCejXdAF
z/7+BSMpAkEA8EaSOeP5Xr3ZrbiKzi6TGMwHMvC7HdJxaBJbVRfApFrE0/mPwmP5
rN7QwjrMY+0+AbXcm8mRQyQ1+IGEembsdwJBAN6az8Rv7QnD/YBvi52POIlRSSIM
V7SwWvSK4WSMnGb1ZBbhgdg57DXaspcwHsFV7hByQ5BvMtIduHcT14ECfcECQATe
aTgjFnqE/lQ22Rk0eGaYO80cc643BXVGafNfd9fcvwBMnk0iGX0XRsOozVt5Azil
psLBYuApa66NcVHJpCECQQDTjI2AQhFc1yRnCU/YgDnSpJVm1nASoRUnU8Jfm3Oz
uku7JUXcVpt08DFSceCEX9unCuMcT72rAQlLpdZir876
-----END RSA PRIVATE KEY-----</textarea><br/>
<label for="pubkey">Public Key</label><br/>
<textarea id="pubkey" rows="15" cols="65">-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDlOJu6TyygqxfWT7eLtGDwajtN
FOb9I5XRb6khyfD1Yt3YiCgQWMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76
xFxdU6jE0NQ+Z+zEdhUTooNRaY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4
gwQco1KRMDSmXSMkDwIDAQAB
-----END PUBLIC KEY-----</textarea><br/>
<label for="input">Text to encrypt:</label><br/>
<textarea id="input" name="input" type="text" rows=4 cols=70>This is a test!</textarea><br/>
<input id="testme" type="button" value="Test Me!!!"/><br/>
</div>
The library you're trying to use doesn't look that promissing for asymetric cryptography.
If you're open for suggestion try using this one.
Here is example code :
<div class="container">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsencrypt/2.3.1/jsencrypt.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script type="text/javascript">
// Call this code when the page is done loading.
jQuery(function () {
// Run a quick encryption/decryption when they click.
jQuery('#testme').click(function () {
// Encrypt with the public key...
var encrypt = new JSEncrypt();
encrypt.setPublicKey($('#pubkey').val());
var encrypted = encrypt.encrypt($('#input').val());
console.log(encrypted);
// Decrypt with the private key...
var decrypt = new JSEncrypt();
decrypt.setPrivateKey($('#privkey').val());
var uncrypted = decrypt.decrypt(encrypted);
// Now a simple check to see if the round-trip worked.
if (uncrypted == $('#input').val()) {
alert('It works!!!');
}
else {
alert('Something went wrong....');
}
});
});
</script>
<label for="privkey">Private Key</label><br/>
<textarea id="privkey" rows="15" cols="65">-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDlOJu6TyygqxfWT7eLtGDwajtNFOb9I5XRb6khyfD1Yt3YiCgQ
WMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76xFxdU6jE0NQ+Z+zEdhUTooNR
aY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4gwQco1KRMDSmXSMkDwIDAQAB
AoGAfY9LpnuWK5Bs50UVep5c93SJdUi82u7yMx4iHFMc/Z2hfenfYEzu+57fI4fv
xTQ//5DbzRR/XKb8ulNv6+CHyPF31xk7YOBfkGI8qjLoq06V+FyBfDSwL8KbLyeH
m7KUZnLNQbk8yGLzB3iYKkRHlmUanQGaNMIJziWOkN+N9dECQQD0ONYRNZeuM8zd
8XJTSdcIX4a3gy3GGCJxOzv16XHxD03GW6UNLmfPwenKu+cdrQeaqEixrCejXdAF
z/7+BSMpAkEA8EaSOeP5Xr3ZrbiKzi6TGMwHMvC7HdJxaBJbVRfApFrE0/mPwmP5
rN7QwjrMY+0+AbXcm8mRQyQ1+IGEembsdwJBAN6az8Rv7QnD/YBvi52POIlRSSIM
V7SwWvSK4WSMnGb1ZBbhgdg57DXaspcwHsFV7hByQ5BvMtIduHcT14ECfcECQATe
aTgjFnqE/lQ22Rk0eGaYO80cc643BXVGafNfd9fcvwBMnk0iGX0XRsOozVt5Azil
psLBYuApa66NcVHJpCECQQDTjI2AQhFc1yRnCU/YgDnSpJVm1nASoRUnU8Jfm3Oz
uku7JUXcVpt08DFSceCEX9unCuMcT72rAQlLpdZir876
-----END RSA PRIVATE KEY-----</textarea><br/>
<label for="pubkey">Public Key</label><br/>
<textarea id="pubkey" rows="15" cols="65">-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDlOJu6TyygqxfWT7eLtGDwajtN
FOb9I5XRb6khyfD1Yt3YiCgQWMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76
xFxdU6jE0NQ+Z+zEdhUTooNRaY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4
gwQco1KRMDSmXSMkDwIDAQAB
-----END PUBLIC KEY-----</textarea><br/>
<label for="input">Text to encrypt:</label><br/>
<textarea id="input" name="input" type="text" rows=4 cols=70>This is a test!</textarea><br/>
<input id="testme" type="button" value="Test Me!!!"/><br/>
</div>
answered Nov 25 '18 at 13:27
Nikola PavlovićNikola Pavlović
11115
11115
Thanks for your suggestion. I am open to other libs as its just for my training. Do you the methods of this lib to create the keypairs inside the browser instead of using openssl genrsa -out rsa_1024_priv.pem 1024 ?
– codebird456
Nov 25 '18 at 14:50
1
Maybe this will help. juhoen.github.io/hybrid-crypto-js
– Nikola Pavlović
Nov 25 '18 at 14:53
this one works well. Fast and easy to play around. Thnaks
– codebird456
Nov 25 '18 at 18:08
add a comment |
Thanks for your suggestion. I am open to other libs as its just for my training. Do you the methods of this lib to create the keypairs inside the browser instead of using openssl genrsa -out rsa_1024_priv.pem 1024 ?
– codebird456
Nov 25 '18 at 14:50
1
Maybe this will help. juhoen.github.io/hybrid-crypto-js
– Nikola Pavlović
Nov 25 '18 at 14:53
this one works well. Fast and easy to play around. Thnaks
– codebird456
Nov 25 '18 at 18:08
Thanks for your suggestion. I am open to other libs as its just for my training. Do you the methods of this lib to create the keypairs inside the browser instead of using openssl genrsa -out rsa_1024_priv.pem 1024 ?
– codebird456
Nov 25 '18 at 14:50
Thanks for your suggestion. I am open to other libs as its just for my training. Do you the methods of this lib to create the keypairs inside the browser instead of using openssl genrsa -out rsa_1024_priv.pem 1024 ?
– codebird456
Nov 25 '18 at 14:50
1
1
Maybe this will help. juhoen.github.io/hybrid-crypto-js
– Nikola Pavlović
Nov 25 '18 at 14:53
Maybe this will help. juhoen.github.io/hybrid-crypto-js
– Nikola Pavlović
Nov 25 '18 at 14:53
this one works well. Fast and easy to play around. Thnaks
– codebird456
Nov 25 '18 at 18:08
this one works well. Fast and easy to play around. Thnaks
– codebird456
Nov 25 '18 at 18:08
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467770%2fhow-to-encrypt-string-using-openpgp-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown