Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

KeyPair object

The KeyPair object holds an internal reference to an asymmetric key pair comprising private and public Key objects.

IE11

 

DOM Information

Inheritance Hierarchy

The KeyPair does not inherit from any class or interface.

Members

The KeyPair object has these types of members:

Properties

The KeyPair object has these properties.

PropertyAccess typeDescription

privateKey

Read/write

Provides access to KeyPair's private key.

publicKey

Read/write

Provides access to KeyPair's public key.

 

Examples


<!DOCTYPE html>

<html>
<head>
  <title>KeyPair</title>
</head>

<body>
  <h1>KeyPair Object</h1>
  <p>
    Open <a href="http://msdn.microsoft.com/en-us/library/ie/gg589512(v=vs.85).aspx">F12 Tools</a> (press F12) to see the
    results of this demo in the <a href="http://msdn.microsoft.com/en-us/library/ie/dn255006(v=vs.85).aspx">Console</a>.
  </p>
  <script>
    "use strict";

    var crypto = window.msCrypto;

    if (crypto.subtle) {
      var genOp = crypto.subtle.generateKey({
        name: "RSAES-PKCS1-v1_5",
        modulusLength: 2048,
        publicExponent: new Uint8Array([0x01, 0x00, 0x01])
      }, true, ["encrypt", "decrypt"]);

      genOp.onerror = function (e) {
        console.error("crypto.subtle.generateKey onerror handler fired.");
      };

      genOp.oncomplete = function (e) {
        var pubKey = e.target.result.publicKey;
        var privKey = e.target.result.privateKey;

        if (pubKey && privKey) {
          console.log("generateKey RSAES-PKCS1-v1_5: PASS");
        } else {
          console.error("generateKey RSAES-PKCS1-v1_5: FAIL");
        }

        if (pubKey.extractable && privKey.extractable) {
          console.log("PubKey & private extractable RSAES-PKCS1-v1_5: PASS");
        } else {
          console.error("PubKey & private extractable RSAES-PKCS1-v1_5: FAIL");
        }
      }; // genOp.oncomplete
    } else {
      console.error("Unable to create window.crypto object.");
    }
  </script>
</body>
</html>

 

 

Show:
© 2015 Microsoft