/** * Represents an RSA KeyPair in a generic format. */ export type KeyPair = { publicKey: T; privateKey: T; }; export declare enum ShaVersion { Sha1 = "sha-1", Sha256 = "sha-256" } export interface RSAUtils { /** * Generates a key pair for encryption/decryption of data. * @param shaVersion the version of the SHA algorithm to use. */ generateKeyPair(shaVersion: ShaVersion): Promise>; /** * Generates a key pair for signing data and signature verification. */ generateSignatureKeyPair(): Promise>; /** * * 'JWK': Json Web key (ref. http://tools.ietf.org/html/draft-ietf-jose-json-web-key-11) * 'spki': for private key * 'pkcs8': for private Key * * @param keyPair is {publicKey: CryptoKey, privateKey: CryptoKey} * @param privKeyFormat will be 'pkcs8' or 'jwk' * @param pubKeyFormat will be 'spki' or 'jwk' * @returns {Promise} will the AES Key */ exportKeys(keyPair: KeyPair, privKeyFormat: 'jwk', pubKeyFormat: 'jwk'): Promise>; exportKeys(keyPair: KeyPair, privKeyFormat: 'pkcs8', pubKeyFormat: 'spki'): Promise>; exportKeys(keyPair: KeyPair, privKeyFormat: string, pubKeyFormat: string): Promise>; /** * Format: * * 'JWK': Json Web key (ref. http://tools.ietf.org/html/draft-ietf-jose-json-web-key-11) * 'spki': for private key * 'pkcs8': for private Key * * @param cryptoKey public or private * @param format either 'jwk' or 'spki' or 'pkcs8' * @returns {Promise|*} will be RSA key (public or private) */ exportKey(cryptoKey: CryptoKey, format: 'jwk'): Promise; exportKey(cryptoKey: CryptoKey, format: 'spki'): Promise; exportKey(cryptoKey: CryptoKey, format: 'pkcs8'): Promise; exportKey(cryptoKey: CryptoKey, format: string): Promise; /** * * @param publicKey (CryptoKey) * @param plainData (Uint8Array) */ encrypt(publicKey: CryptoKey, plainData: Uint8Array): Promise; /** * * @param privateKey (CryptoKey) * @param encryptedData (Uint8Array) */ decrypt(privateKey: CryptoKey, encryptedData: Uint8Array): Promise; /** * * @param format 'jwk', 'spki', or 'pkcs8' * @param keydata should be the key data based on the format. * @param keyUsages Array of usages. For example, ['encrypt'] for public key. * @param hashAlgorithm 'sha-1' or 'sha-256' * @returns {*} */ importKey(format: 'jwk' | 'spki' | 'pkcs8', keydata: JsonWebKey | ArrayBuffer, keyUsages: KeyUsage[], hashAlgorithm: ShaVersion): Promise; importSignatureKey(format: 'jwk' | 'pkcs8', keydata: JsonWebKey | ArrayBuffer): Promise; importVerificationKey(format: 'jwk' | 'spki', keydata: JsonWebKey | ArrayBuffer): Promise; /** * * @param format 'jwk' or 'pkcs8' * @param keydata should be the key data based on the format. * @param hashAlgorithm 'sha-1' or 'sha-256' * @returns {*} */ importPrivateKey(format: 'jwk' | 'pkcs8', keydata: JsonWebKey | ArrayBuffer, hashAlgorithm: ShaVersion): Promise; /** * * @param privateKeyFormat 'jwk' or 'pkcs8' * @param privateKeydata should be the key data based on the format. * @param publicKeyFormat 'jwk' or 'spki' * @param publicKeyData should be the key data based on the format. * @param hashAlgorithm 'sha-1' or 'sha-256' * @returns {Promise|*} */ importKeyPair(privateKeyFormat: 'jwk' | 'pkcs8', privateKeydata: JsonWebKey | ArrayBuffer, publicKeyFormat: 'jwk' | 'spki', publicKeyData: JsonWebKey | ArrayBuffer, hashAlgorithm: ShaVersion): Promise>; /** * Tries to encrypt then decrypt data using a keypair. If both operations succeed without throwing an error and the decrypted data matches the * original data returns true, else false. * @param keyPair a key pair. * @return if the key pair could be successfully used to encrypt then decrypt data. */ checkKeyPairValidity(keyPair: KeyPair): Promise; /** * Generates a signature for some data. The signature algorithm used is RSA-PSS with SHA-256. * @param privateKey private key to use for signature * @param data the data to sign * @return the signature. */ sign(privateKey: CryptoKey, data: ArrayBuffer): Promise; /** * Verifies if a signature matches the data. The signature algorithm used is RSA-PSS with sha-256. * @param publicKey public key to use for signature verification. * @param signature the signature to verify * @param data the data that was signed * @return if the signature matches the data and key. */ verifySignature(publicKey: CryptoKey, signature: ArrayBuffer, data: ArrayBuffer): Promise; } export declare class RSAUtilsImpl implements RSAUtils { /********* RSA Config **********/ rsaParams: any; rsaHashedParams: any; rsaWithSha256HashedParams: any; private readonly signatureKeysGenerationParams; private crypto; constructor(crypto?: Crypto); /** * Generates a key pair for encryption/decryption of data. * @param shaVersion the version of the SHA algorithm to use. */ generateKeyPair(shaVersion: ShaVersion): Promise>; /** * Generates a key pair for signing data and signature verification. */ generateSignatureKeyPair(): Promise>; /** * * 'JWK': Json Web key (ref. http://tools.ietf.org/html/draft-ietf-jose-json-web-key-11) * 'spki': for private key * 'pkcs8': for private Key * * @param keyPair is {publicKey: CryptoKey, privateKey: CryptoKey} * @param privKeyFormat will be 'pkcs8' or 'jwk' * @param pubKeyFormat will be 'spki' or 'jwk' * @returns {Promise} will the AES Key */ exportKeys(keyPair: KeyPair, privKeyFormat: 'jwk', pubKeyFormat: 'jwk'): Promise>; exportKeys(keyPair: KeyPair, privKeyFormat: 'pkcs8', pubKeyFormat: 'spki'): Promise>; /** * Format: * * 'JWK': Json Web key (ref. http://tools.ietf.org/html/draft-ietf-jose-json-web-key-11) * 'spki': for private key * 'pkcs8': for private Key * * @param cryptoKey public or private * @param format either 'jwk' or 'spki' or 'pkcs8' * @returns {Promise|*} will be RSA key (public or private) */ exportKey(cryptoKey: CryptoKey, format: 'jwk'): Promise; exportKey(cryptoKey: CryptoKey, format: 'spki'): Promise; exportKey(cryptoKey: CryptoKey, format: 'pkcs8'): Promise; /** * * @param publicKey (CryptoKey) * @param plainData (Uint8Array) */ encrypt(publicKey: CryptoKey, plainData: Uint8Array): Promise; /** * * @param privateKey (CryptoKey) * @param encryptedData (Uint8Array) */ decrypt(privateKey: CryptoKey, encryptedData: Uint8Array): Promise; /** * * @param format 'jwk', 'spki', or 'pkcs8' * @param keydata should be the key data based on the format. * @param keyUsages Array of usages. For example, ['encrypt'] for public key. * @param hashAlgorithm 'sha-1' or 'sha-256' * @returns {*} */ importKey(format: 'jwk' | 'spki' | 'pkcs8', keydata: JsonWebKey | ArrayBuffer, keyUsages: KeyUsage[], hashAlgorithm: ShaVersion): Promise; importSignatureKey(format: 'jwk' | 'pkcs8', keydata: JsonWebKey | ArrayBuffer): Promise; importVerificationKey(format: 'jwk' | 'spki', keydata: JsonWebKey | ArrayBuffer): Promise; paramsForCreationOrImport(shaVersion: ShaVersion): any; /** * * @param format 'jwk' or 'pkcs8' * @param keydata should be the key data based on the format. * @param hashAlgorithm 'sha-1' or 'sha-256' * @returns {*} */ importPrivateKey(format: 'jwk' | 'pkcs8', keydata: JsonWebKey | ArrayBuffer, hashAlgorithm: ShaVersion): Promise; /** * * @param privateKeyFormat 'jwk' or 'pkcs8' * @param privateKeydata should be the key data based on the format. * @param publicKeyFormat 'jwk' or 'spki' * @param publicKeyData should be the key data based on the format. * @param hashAlgorithm 'sha-1' or 'sha-256' * @returns {Promise|*} */ importKeyPair(privateKeyFormat: string, privateKeydata: JsonWebKey | ArrayBuffer, publicKeyFormat: string, publicKeyData: JsonWebKey | ArrayBuffer, hashAlgorithm: ShaVersion): Promise>; /** * Tries to encrypt then decrypt data using a keypair. If both operations succeed without throwing an error and the decrypted data matches the * original data returns true, else false. * @param keyPair a key pair. * @return if the key pair could be successfully used to encrypt then decrypt data. */ checkKeyPairValidity(keyPair: KeyPair): Promise; /** * Generates a signature for some data. The signature algorithm used is RSA-PSS with SHA-256. * @param privateKey private key to use for signature * @param data the data to sign * @return the signature. */ sign(privateKey: CryptoKey, data: ArrayBuffer): Promise; /** * Verifies if a signature matches the data. The signature algorithm used is RSA-PSS with sha-256. * @param publicKey public key to use for signature verification. * @param signature the signature to verify * @param data the data that was signed * @return if the signature matches the data and key. */ verifySignature(publicKey: CryptoKey, signature: ArrayBuffer, data: ArrayBuffer): Promise; } export declare const RSA: RSAUtils;