Skip to content

infinity.rsa

Provides RSA encryption, decryption, signing and verification functionality for strings, files and streams.

Module: infinity.crypto

Interfaces:
Functions:

Example:

infinity.loadModule('infinity.crypto');
let data = "Hello World";
let key = infinity.rsa.generateKeys(1024);
let asymKey = infinity.rsa.encrypt(data, key.public);
console.debug(asymKey);
//IAAAAFYyQRxvX3f/zyzw3k0ZBbkFRUOALP9ZUOzBUyOuB0k3kUnFuL5ZEDiNvDbjw398jF3LW41HBeuxdxysWpgoeVp/iGrHZ3avDXjI/AFjr+RjPB6CRYqOb6iQeHuxqghgouz6fGqx33K9FkIrcaaiCSuyMk0CxuXNJxpPj3iAsczw3BqsKoy5Qu9qpko2yJ1g7Yj2Bg==
console.debug(infinity.rsa.decrypt(asymKey, key.private)); 
//Hello World

Interfaces

keys

Properties:


Properties


private

Type: string

Contains the private rsa key.


public

Type: string

Contains the public rsa key.


Functions

decrypt()

Attempts to decrypt the given string with RSA using the provided private key and returns the results.

Signature:

decrypt( value: string, privateKey: string ): string

Parameters:

  • value: string

    The string to decrypt.

  • privateKey: string

    The private rsa key.

Return type: string

Example:

infinity.loadModule('infinity.crypto');
let decryptedData = infinity.rsa.decrypt(encryptedData, privateKey);

encrypt()

Encrypts the given string with RSA using the provided public key and returns the results.

Signature:

encrypt( value: string, publicKey: string ): string

Parameters:

  • value: string

    The data to encrypt.

  • publicKey: string

    The password to be used later for decryption.

Return type: string

Example:

infinity.loadModule('infinity.crypto');
let encryptedData = infinity.rsa.encrypt(dataToEncrypt, publicKey);

generateKeys()

Returns a public and a private RSA key, generated according to the specified modulus bit length.

Signature:

generateKeys( bits: number ): infinity.rsa.keys

Parameters:

  • bits: number

    The number of bits in the modulus.

Return type: infinity.rsa.keys

Example:

infinity.loadModule('infinity.crypto');
let keys = infinity.rsa.generateKeys(1024);
console.debug(keys.private);
console.debug(keys.public);

sign()

Returns the RSA-signature for a provided string, generated with the provided private key.

Signature:

sign( value: string, privateKey: string ): string

Parameters:

  • value: string

    The string to create the signature for.

  • privateKey: string

    The private rsa key.

Return type: string

Example:

infinity.loadModule('infinity.crypto');
let signature = infinity.rsa.sign(dataToSign, privateKey);

verify()

Returns whether the given string can be verified with RSA using the provided signature and public key.

Signature:

verify( value: string, publicKey: string, signature: string ): boolean

Parameters:

  • value: string

    The data to verify.

  • publicKey: string

    The public rsa key.

  • signature: string

    The provided signature.

Return type: boolean

Example:

infinity.loadModule('infinity.crypto');
if ( infinity.rsa.verify(dataToVerify, publicKey, signature) ) {
  //...
}