Helper method to convert the VAPID key to a UInt8 array and supply it to applicationServerKey.
776667
function urlB64ToUint8Array(base64String) {
    const padding = '='.repeat((4 - base64String.length % 4) % 4);
    const base64 = (base64String + padding)
        .replace(/\-/g, '+')
        .replace(/_/g, '/');

    const rawData = self.atob(base64);
    const outputArray = new Uint8Array(rawData.length);

    for (let i = 0; i < rawData.length; ++i) {
        outputArray[i] = rawData.charCodeAt(i);
    }
    return outputArray;
}
15610
public SshKeyPair toKeyPair(String passphrase) throws IOException,
			InvalidPassphraseException {

		ByteArrayReader bar = new ByteArrayReader(decryptKey(passphrase));

		try {
			// Process the actual key and return the key pair

			String algorithm = bar.readString();

			if (algorithm.equals("ssh-dss")) {
				BigInteger p = bar.readBigInteger();
				BigInteger q = bar.readBigInteger();
				BigInteger g = bar.readBigInteger();
				BigInteger x = bar.readBigInteger();

				SshDsaPrivateKey prv = ComponentManager.getInstance()
						.createDsaPrivateKey(p, q, g, x, g.modPow(x, p));
				SshKeyPair pair = new SshKeyPair();

				pair.setPublicKey(prv.getPublicKey());
				pair.setPrivateKey(ComponentManager.getInstance()
						.createDsaPrivateKey(p, q, g, x, g.modPow(x, p)));

				return pair;

			} else if (algorithm.equals("ssh-rsa")) {

				BigInteger publicExponent = bar.readBigInteger();
				BigInteger modulus = bar.readBigInteger();

				// Read the private key
				BigInteger privateExponent = bar.readBigInteger();

				SshKeyPair pair = new SshKeyPair();
				pair.setPublicKey(ComponentManager.getInstance()
						.createRsaPublicKey(modulus, publicExponent));
				pair.setPrivateKey(ComponentManager.getInstance()
						.createRsaPrivateKey(modulus, privateExponent));

				return pair;

			} else {
				throw new IOException("Unsupported private key algorithm type "
						+ algorithm);
			}
		} catch (SshException e) {
			throw new SshIOException(e);
		} finally {
			try {
				bar.close();
			} catch (IOException e) {
			}
		}

	}
1027607
public static byte[] generateKey()
        throws GeneralSecurityException
    {
        KeyGenerator keyGenerator = KeyGenerator.getInstance(KEY_ALGORITHM);
        // java max 128
        keyGenerator.init(128);
        SecretKey secretKey = keyGenerator.generateKey();
        return secretKey.getEncoded();
    }
375391
private byte[] hmac(byte[] key, byte[] str) throws SmackSaslException {
        try {
            return scramHmac.hmac(key, str);
        }
        catch (InvalidKeyException e) {
            throw new SmackSaslException(getName() + " Exception", e);
        }
    }
416586
private static final synchronized void setIVS8(byte[] key) {
        if (ivs8 == null) {
            byte[] iv8 = new byte[8];
            for (int i = 0; i < 8; i++) {
                iv8[i] = key[i];
            }
            ivs8 = new IvParameterSpec(iv8);
        }
    }
1194856
def rsa_private_key_pkcs1_to_pkcs8(pkcs1_key):
    """"""
    algorithm = RsaAlgorithmIdentifier()
    algorithm["rsaEncryption"] = RSA_ENCRYPTION_ASN1_OID

    pkcs8_key = PKCS8PrivateKey()
    pkcs8_key["version"] = 0
    pkcs8_key["privateKeyAlgorithm"] = algorithm
    pkcs8_key["privateKey"] = pkcs1_key

    return encoder.encode(pkcs8_key)
1095604
public static byte[] hmacSha1(final byte[] input, final byte[] key)
		throws GeneralSecurityException {
		try {
			SecretKey secretKey = new SecretKeySpec(key, HMACSHA1_NAME);
			Mac mac = Mac.getInstance(HMACSHA1_NAME);
			mac.init(secretKey);
			return mac.doFinal(input);
		} catch (NoSuchAlgorithmException e) {
			throw new ImpossibleException(e);
		}
	}
723452
public static byte[] computePubkey(byte[] seckey) throws AssertFailException {
        Preconditions.checkArgument(seckey.length == 32);

        ByteBuffer byteBuff = nativeECDSABuffer.get();
        if (byteBuff == null || byteBuff.capacity() < seckey.length) {
            byteBuff = ByteBuffer.allocateDirect(seckey.length);
            byteBuff.order(ByteOrder.nativeOrder());
            nativeECDSABuffer.set(byteBuff);
        }
        byteBuff.rewind();
        byteBuff.put(seckey);

        byte[][] retByteArray;

        r.lock();
        try {
            retByteArray = secp256k1_ec_pubkey_create(byteBuff, Secp256k1Context.getContext());
        } finally {
            r.unlock();
        }

        byte[] pubArr = retByteArray[0];
        int pubLen = new BigInteger(new byte[] { retByteArray[1][0] }).intValue();
        int retVal = new BigInteger(new byte[] { retByteArray[1][1] }).intValue();

        assertEquals(pubArr.length, pubLen, "Got bad pubkey length.");

        return retVal == 0 ? new byte[0] : pubArr;
    }
1057290
def rsa_public_key_pkcs1_to_pkcs8(pkcs1_key):
    """"""
    algorithm = RsaAlgorithmIdentifier()
    algorithm["rsaEncryption"] = RSA_ENCRYPTION_ASN1_OID

    pkcs8_key = PublicKeyInfo()
    pkcs8_key["algorithm"] = algorithm
    pkcs8_key["publicKey"] = univ.BitString.fromOctetString(pkcs1_key)

    return encoder.encode(pkcs8_key)
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")))
625640
function toUint8Array(object) {
    if (object instanceof Uint8Array) return object;
    if (Array.isArray(object)) return new Uint8Array(object);
    if (('byteOffset' in object) && ('byteLength' in object)) {
      var array = new Array(object.byteLength);
      for (var i = 0; i < object.byteLength; i++) {
        array[i] = object[i + object.byteOffset];
      }
      return new Uint8Array(array);
    }
    throw new Error("Unable to create Uint8Array");
  }
648656
def generate_key_data_from_nonce(server_nonce, new_nonce):
    """"""
    server_nonce = server_nonce.to_bytes(16, 'little', signed=True)
    new_nonce = new_nonce.to_bytes(32, 'little', signed=True)
    hash1 = sha1(new_nonce + server_nonce).digest()
    hash2 = sha1(server_nonce + new_nonce).digest()
    hash3 = sha1(new_nonce + new_nonce).digest()

    key = hash1 + hash2[:12]
    iv = hash2[12:20] + hash3 + new_nonce[:4]
    return key, iv
1121052
def codes_get_bytes_array(handle, key, size):
    # type: (cffi.FFI.CData, str, int) -> T.List[int]
    
    values = ffi.new('unsigned char[]', size)
    size_p = ffi.new('size_t *', size)
    _codes_get_bytes(handle, key.encode(ENC), values, size_p)
    return list(values)
152432
def _GetBytes(partition_key):
        
        if isinstance(partition_key, six.string_types):
            return bytearray(partition_key, encoding='utf-8')
        else:
            raise ValueError("Unsupported " + str(type(partition_key)) + " for partitionKey.")
121472
private byte[] hmac(byte[] key, byte[] data) {
        try {
            final Mac mac = Mac.getInstance(hmacAlgorithm);
            mac.init(new SecretKeySpec(key, mac.getAlgorithm()));
            return mac.doFinal(data);
        } catch (InvalidKeyException e) {
            if (key.length == 0) {
                throw new UnsupportedOperationException("This JVM does not support empty HMAC keys (empty passwords). "
                        + "Please set a bucket password or upgrade your JVM.");
            } else {
                throw new RuntimeException("Failed to generate HMAC hash for password", e);
            }
        } catch (Throwable t) {
            throw new RuntimeException(t);
        }
    }
1207779
static ByteBuffer getRowKeyRaw(int shardId, long tableUuid, byte[] contentKeyBytes) {
        checkArgument(shardId >= 0 && shardId < 256);

        // Assemble a single array which is "1 byte shard id + 8 byte table uuid + n-byte content key".
        ByteBuffer rowKey = ByteBuffer.allocate(9 + contentKeyBytes.length);
        rowKey.put((byte) shardId);
        rowKey.putLong(tableUuid);
        rowKey.put(contentKeyBytes);

        rowKey.flip();
        return rowKey;
    }
956699
public byte[] init(byte[] key){
		byte[] iv = new byte[blockSize];
		new SecureRandom().nextBytes(iv);
		init(iv, key);
		return iv;
	}