HybridCryptography (Core) Guide - adonisv79/swish-protocol GitHub Wiki

Interfaces

  • AESKeySet - An object containing necessary values used for AES cryptography
    • key (Buffer) - the 16 byte AES encryption key
    • iv (Buffer) - the 16 byte AES initialization vector
  • RSAKeySet - An object containing the public and private key values used for RSA cryptography
    • private (string) - The private RSA key
    • public (string) - The publicRSA key
  • SwishKeys - defines the structure of the Swish key set passed between transmissions
    • swishIV (string) - the encrypted initialization vector to be used for the AES encryption/decryption
    • swishKey (string) - the encrypted AES key to be used for the AES encryption/decryption
    • swishNextPublic (string) - the encrypted public key to be used for the next request/response
  • SwishHeaders - defines the structure of the Swish headers that is passed between client browser and the server. this extends the interface SwishKeys and thus contains all its properties
    • swishAction (string) - defines the action being rendered
    • swishSessionId (string) - the session identifier used by a server implementing swish to identify user session
  • SwishBody - defines the structure of a swish body message
    • enc_body (string) - this is the encrypted payload content in base64 format
    • is_json (boolean) - indicates if the payload is originally a JSON object
  • SwishPackage -Defines an ancapsulated object containing the swish header and body
    • headers (SwishHeaders) - The Swish request header data
    • body (SwishBody) - The Swish request body data
  • HybridEncryptResult - Defines the response object of the hybrid encryption process
    • createdDate (number) - defines the timestamp the new swish encryptions are generated
    • body (SwishBody) - The encrypted data
    • keys (SwishKeys) - The generated swish keys
    • nextPrivate (string) - The next private key to be used
  • HybridDecryptResult- Defines the response object of the hybrid decryption process
    • data (Buffer) - The decrypted buffer value of the data
    • nextPublic(string) - The next private key to be used

Functions

createAESEncryptionKey

Creates an randomized AESKeySet

aesEncrypt

Applies AES Encryption using an AES key and iv and returns the encrypted data (in base64 string form)

Parameters

  • data (crypto.BinaryLike) - The data to encrypt
  • aes (AESKeySet ) - The AES Key Set which contains the key and initialization vector values

aesDecrypt

Applies AES Decryption to the base64+AES encrypted data using an AES key and iv and returns the decrypted data in its string or JSON object form)

Parameters

  • encData (string) - The encrypted data to unpack
  • isJson (boolean) - Indicates if it was originally a JSON object
  • aes (AESKeySet ) - The AES Key Set which contains the key and initialization vector values

createRSAEncrytptionKeys

Creates a new RSAKeySet (public-private) key value pair

Parameters

  • passphrase (string) - The special passphrase to use the decryption/private key

hybridEncrypt

Encrypts the data with AES and then encrypts the AES keys with RSA and returns a new HybridEncryptResult object.

Parameters

  • data (BinaryLike | object) - The data to encrypt. If this is an object, returned 'isJson' will be set to true
  • rsaPub (string) - the RSA public string to use for encryption

hybridDecrypt

Decrypts the hybrid encrypted data and returns the HybridDecryptResult

Parameters

  • body (SwishBody) - The payload to decrypt
  • keys (SwishKeys) - The SwishKeys that contain information on how to decrypt the data and the next public in the chain
  • privateKey (string) - the next private key for decryption in the chain
  • passphrase (string) - the Passphrase used to generate the RSA private key