tansuo 发表于 2023-12-8 16:11:36

RSA加密

> 本帖最后由 tansuo 于 2023-12-8 19:02 编辑

下面油猴脚本exportKey参数为jwk时 公钥私钥都有值,参数为pkcs8和spki时公钥私钥的值为{}

```js
// ==UserScript==
// @name         New RSA
// @namespace    http://tampermonkey.net/
// @version      0.1
// @descriptiontry to take over the world!
// @author       You
// @match      http://127.0.0.1/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=0.1
// @grant      none
// ==/UserScript==
(function() {
    'use strict';
      window.crypto.subtle.generateKey(
            {
                name: 'RSA-OAEP',
                modulusLength: 2048,
                publicExponent: new Uint8Array(),
                hash: {
                  name: 'SHA-512'
                }
            },
            true,
            ['encrypt', 'decrypt']
      ).then(function(keyPair) {
            window.crypto.subtle.exportKey('pkcs8', keyPair.privateKey).then(function(privateKey) {
                window.crypto.subtle.exportKey('spki', keyPair.publicKey).then(function(publicKey) {
                  var privateKeyStr = JSON.stringify(privateKey);
                  var publicKeyStr = JSON.stringify(publicKey);
                  console.log("Private Key:", privateKeyStr);
                  console.log("Public Key:", publicKeyStr);
debugger;
                  // 调用其他函数或操作
                });
            });
      });
})();
```

tansuo 发表于 2023-12-16 12:27:37

己经解决
页: [1]
查看完整版本: RSA加密