Create a new pair of public and private key pair to use.
979642
def newkeys(nbits=1024):
        
        pubkey, privkey = rsa.newkeys(nbits, poolsize=1)
        return pubkey, privkey
50341
function KeyPair(privkey) {
  if (!(this instanceof KeyPair)) {
    return new KeyPair(privkey);
  }

  if (privkey) {
    this._keypair = ecdsa.keyFromPrivate(privkey);
  } else {
    this._keypair = ecdsa.genKeyPair();
  }
}
1361123
def regenerate_keypair(private_key, public_key_compressed: false)

      autorelease do |pool|

        eckey = pool.new_ec_key

        priv_bn = pool.new_bn(private_key)

        pub_key = pool.new_ec_point
        EC_POINT_mul(self.group, pub_key, priv_bn, nil, nil, pool.bn_ctx)
        EC_KEY_set_private_key(eckey, priv_bn)
        EC_KEY_set_public_key(eckey, pub_key)

        length = i2d_ECPrivateKey(eckey, nil)
        buf = FFI::MemoryPointer.new(:uint8, length)
        if i2d_ECPrivateKey(eckey, pointer_to_pointer(buf)) == length
          # We have a full DER representation of private key, it contains a length
          # of a private key at offset 8 and private key at offset 9.
          size = buf.get_array_of_uint8(8, 1)[0]
          private_key2 = buf.get_array_of_uint8(9, size).pack("C*").rjust(32, "\x00")
        else
          raise BTCError, "OpenSSL failed to convert private key to DER format"
        end

        if private_key2 != private_key
          raise BTCError, "OpenSSL somehow regenerated a wrong private key."
        end

        EC_KEY_set_conv_form(eckey, public_key_compressed ? POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED);

        length = i2o_ECPublicKey(eckey, nil)
        buf = FFI::MemoryPointer.new(:uint8, length)
        if i2o_ECPublicKey(eckey, pointer_to_pointer(buf)) == length
          public_key = buf.read_string(length)
        else
          raise BTCError, "OpenSSL failed to regenerate a public key."
        end

        [ private_key2, public_key ]
      end
    end
438909
def FromPublicKey(cls, public_key):
    """"""
    # Our CN will be the first 64 bits of the hash of the public key
    # in MPI format - the length of the key in 4 bytes + the key
    # prefixed with a 0. This weird format is an artifact from the way
    # M2Crypto handled this, we have to live with it for now.
    n = public_key.GetN()
    raw_n = binascii.unhexlify("%x" % n)

    mpi_format = struct.pack(">i", len(raw_n) + 1) + b"\x00" + raw_n

    digest = binascii.hexlify(hashlib.sha256(mpi_format).digest()[:8])
    return cls("C.{}".format(digest.decode("ascii")))
776194
def add_key(pub):
    """"""
    global _server_keys
    key = rsa.PublicKey.load_pkcs1(pub)
    _server_keys[_compute_fingerprint(key)] = key
142847
def generate_private_key(key_size=2048):
    """"""
    return cryptography.hazmat.primitives.asymmetric.rsa.generate_private_key(
        public_exponent=65537,
        key_size=key_size,
        backend=cryptography.hazmat.backends.default_backend(),
    )
1331093
public static KeySpec newPBEKeySpec(final String privateKey)
	{
		if (privateKey == null)
		{
			return new PBEKeySpec(CompoundAlgorithm.PRIVATE_KEY.toCharArray());
		}
		return new PBEKeySpec(privateKey.toCharArray());
	}
1124840
def keys_create(gandi, fqdn, flag):
    """"""
    key_info = gandi.dns.keys_create(fqdn, int(flag))

    output_keys = ['uuid', 'algorithm', 'algorithm_name', 'ds', 'fingerprint',
                   'public_key', 'flags', 'tag', 'status']
    output_generic(gandi, key_info, output_keys, justify=15)
    return key_info
592934
def create(cls, api_context, public_key_string):
        

        api_client = client.ApiClient(api_context)
        body_bytes = cls.generate_request_body_bytes(
            public_key_string
        )
        response_raw = api_client.post(cls._ENDPOINT_URL_POST, body_bytes, {})

        return cls._from_json_array_nested(response_raw)
282107
def add(self, pubkey):
        
        f = get_fingerprint_from_public_key(pubkey)
        if f not in self._keys:
            self._order[len(self._keys)] = f
            self._keys[f] = pubkey
1211281
public KeyPair generateKeyPair() {
        KeyPair keyPair = null;
        try {
            KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(ALGORITHM);
            keyPairGenerator.initialize(KEYLENGTH);
            keyPair = keyPairGenerator.generateKeyPair();
        } catch (NoSuchAlgorithmException e) {
            LOG.error("Failed to create publi/private key pair", e);
        }
        
        return keyPair;
    }
107420
function genPrivKey(){
	var privKey;
	do {
		console.log("generating new priv key");
		privKey = crypto.randomBytes(32);
	}
	while (!ecdsa.privateKeyVerify(privKey));
	return privKey;
}
533948
def create(gandi, resource, flags, algorithm, public_key):
    """"""

    result = gandi.dnssec.create(resource, flags, algorithm, public_key)

    return result
1134366
def create_public_key_from_json(values):
        """"""
        # currently we only support RSA public keys
        _id = values.get('id')
        if not _id:
            # Make it more forgiving for now.
            _id = ''
            # raise ValueError('publicKey definition is missing the "id" value.')

        if values.get('type') == PUBLIC_KEY_TYPE_RSA:
            public_key = PublicKeyRSA(_id, owner=values.get('owner'))
        else:
            public_key = PublicKeyBase(_id, owner=values.get('owner'), type='EthereumECDSAKey')

        public_key.set_key_value(values)
        return public_key
198378
async function createPrivateKey(size = 2048) {
    let pemKey;

    /* Native implementation */
    if (nativeGenKeyPair) {
        const result = await nativeGenKeyPair('rsa', {
            modulusLength: size,
            publicKeyEncoding: { type: 'spki', format: 'pem' },
            privateKeyEncoding: { type: 'pkcs8', format: 'pem' }
        });

        pemKey = result[1];
    }
    /* Forge implementation */
    else {
        const keyPair = await forgeGenKeyPair({ bits: size });
        pemKey = forge.pki.privateKeyToPem(keyPair.privateKey);
    }

    return Buffer.from(pemKey);
}
1172365
def sec_to_public_pair(sec, generator=None, strict=True):
    """"""
    byte_count = (generator.p().bit_length() + 7) >> 3 if generator else (len(sec) - 1)
    x = from_bytes_32(sec[1:1 + byte_count])
    sec0 = sec[:1]
    if len(sec) == 1 + byte_count * 2:
        isok = sec0 == b'\4'
        if not strict:
            isok = isok or (sec0 in [b'\6', b'\7'])
        if isok:
            y = from_bytes_32(sec[1+byte_count:1+2*byte_count])
            return (x, y)
    elif len(sec) == 1 + byte_count:
        if not strict or (sec0 in (b'\2', b'\3')):
            is_y_odd = (sec0 != b'\2')
            return generator.points_for_x(x)[is_y_odd]
    raise EncodingError("bad sec encoding for public key")
25832
def generate(cls):
        
        return cls(libnacl.randombytes(PrivateKey.SIZE), encoder=encoding.RawEncoder)