crypto#KeyObject TypeScript Examples

The following examples show how to use crypto#KeyObject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: provider.ts    From backstage with Apache License 2.0 6 votes vote down vote up
getKey = async (header: JWTHeaderParameters): Promise<KeyObject> => {
    if (!header.kid) {
      throw new AuthenticationError('No key id was specified in header');
    }
    const optionalCacheKey = this.keyCache.get<KeyObject>(header.kid);
    if (optionalCacheKey) {
      return crypto.createPublicKey(optionalCacheKey);
    }
    const keyText: string = await fetch(
      `https://public-keys.auth.elb.${encodeURIComponent(
        this.region,
      )}.amazonaws.com/${encodeURIComponent(header.kid)}`,
    ).then(response => response.text());
    const keyValue = crypto.createPublicKey(keyText);
    this.keyCache.set(
      header.kid,
      keyValue.export({ format: 'pem', type: 'spki' }),
    );
    return keyValue;
  };
Example #2
Source File: JwtGuard.ts    From adonis5-jwt with MIT License 5 votes vote down vote up
/**
     * Converts key string to Buffer
     */
    private generateKey(hash: string): KeyObject {
        return createPrivateKey(Buffer.from(hash));
    }