mirror of
https://github.com/bitwarden/help
synced 2026-01-05 18:13:15 +00:00
generate rsa keypair
This commit is contained in:
65
crypto.html
65
crypto.html
@@ -19,6 +19,12 @@
|
||||
<script src="//oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
|
||||
<script src="//oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
<style>
|
||||
body {
|
||||
padding: 50px 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container" id="app">
|
||||
@@ -48,23 +54,23 @@
|
||||
</form>
|
||||
|
||||
<h2>User Key</h2>
|
||||
<p>{{userKey.b64}}</p>
|
||||
<pre>{{userKey.b64}}</pre>
|
||||
|
||||
<h2>Master Password Hash</h2>
|
||||
<p>{{userKeyHash.b64}}</p>
|
||||
<pre>{{userKeyHash.b64}}</pre>
|
||||
|
||||
<h2>Generated Symmetric Key Material</h2>
|
||||
<p>{{key.key.b64}}</p>
|
||||
<pre>{{key.key.b64}}</pre>
|
||||
<h3>Encryption Key</h3>
|
||||
<p>{{key.encKey.b64}}</p>
|
||||
<pre>{{key.encKey.b64}}</pre>
|
||||
<h3>MAC Key</h3>
|
||||
<p>{{key.macKey.b64}}</p>
|
||||
<pre>{{key.macKey.b64}}</pre>
|
||||
|
||||
<h2>Generated RSA Keypair</h2>
|
||||
<h3>Public Key</h3>
|
||||
<p></p>
|
||||
<pre>{{publicKey.b64}}</pre>
|
||||
<h3>Private Key</h3>
|
||||
<p></p>
|
||||
<pre>{{privateKey.b64}}</pre>
|
||||
|
||||
<button type="button" id="deriveKeys" class="btn btn-primary" v-on:click="generateKeys">
|
||||
Regenerate Keys
|
||||
@@ -77,17 +83,17 @@
|
||||
<form>
|
||||
<div class="form-group">
|
||||
<label for="plaintext">Plaintext Value</label>
|
||||
<input type="text" id="plaintext" class="form-control" v-model="plaintext">
|
||||
<textarea id="plaintext" class="form-control" v-model="plaintext"></textarea>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<hr />
|
||||
|
||||
<h2>The "Cipher String"</h2>
|
||||
<p>{{cipher.string}}</p>
|
||||
<pre>{{cipher.string}}</pre>
|
||||
|
||||
<h2>Decrypt</h2>
|
||||
<p>{{decPlaintext}}</p>
|
||||
<textarea class="form-control" v-model="decPlaintext" readonly></textarea>
|
||||
</div>
|
||||
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
|
||||
@@ -339,6 +345,32 @@
|
||||
return dataForMac;
|
||||
}
|
||||
|
||||
function generateRsaKeypair() {
|
||||
var rsaOptions = {
|
||||
name: 'RSA-OAEP',
|
||||
modulusLength: 2048,
|
||||
publicExponent: new Uint8Array([0x01, 0x00, 0x01]), // 65537
|
||||
hash: { name: 'SHA-1' }
|
||||
};
|
||||
|
||||
var keypair, publicKey;
|
||||
return window.crypto.subtle.generateKey(rsaOptions, true, ['encrypt', 'decrypt'])
|
||||
.then(function (generatedKey) {
|
||||
keypair = generatedKey;
|
||||
return window.crypto.subtle.exportKey('spki', keypair.publicKey);
|
||||
}).then(function (exportedKey) {
|
||||
publicKey = new ByteData(exportedKey);
|
||||
return window.crypto.subtle.exportKey('pkcs8', keypair.privateKey);
|
||||
}).then(function (exportedKey) {
|
||||
return {
|
||||
publicKey: publicKey,
|
||||
privateKey: new ByteData(exportedKey)
|
||||
};
|
||||
}).catch(function (err) {
|
||||
console.error(err);
|
||||
});
|
||||
}
|
||||
|
||||
// App
|
||||
|
||||
var vm = new Vue({
|
||||
@@ -350,8 +382,8 @@
|
||||
userKey: new ByteData(),
|
||||
userKeyHash: new ByteData(),
|
||||
key: new SymmetricCryptoKey(),
|
||||
publicKey: null,
|
||||
privateKey: null,
|
||||
publicKey: new ByteData(),
|
||||
privateKey: new ByteData(),
|
||||
plaintext: '',
|
||||
cipher: new Cipher(),
|
||||
decPlaintext: ''
|
||||
@@ -383,9 +415,16 @@
|
||||
},
|
||||
methods: {
|
||||
generateKeys: function () {
|
||||
var self = this;
|
||||
|
||||
var key = new Uint8Array(512 / 8);
|
||||
window.crypto.getRandomValues(key);
|
||||
this.key = new SymmetricCryptoKey(key);
|
||||
self.key = new SymmetricCryptoKey(key);
|
||||
|
||||
generateRsaKeypair().then(function (keypair) {
|
||||
self.publicKey = keypair.publicKey;
|
||||
self.privateKey = keypair.privateKey;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user