gx-twofish64
Version:
A library for encrypting and decrypting data using the Twofish algorithm and Base64 encoding. Based on the Genexus implementation (Encrypt64 and Decrypt64).
52 lines (33 loc) ⢠1.43 kB
Markdown
# gx-twofish64
Encryption and decryption compatible with **GeneXus**, using the **Twofish** algorithm and **Base64** encoding.
This package replicates the logic of `Encrypt64` and `Decrypt64` used in GeneXus, allowing interoperability with systems developed on that platform.
## Installation
```bash
npm install gx-twofish64
```
# Usage
```ts
import { encrypt64, decrypt64 } from 'gx-twofish64'
const text = 'Hola mundo'
const hexKey = '21972247ba570855360dbf70c8fa2e0e' // Valid hexadecimal key (32 chars for 128 bits)
const encrypted = encrypt64(text, hexKey)
console.log('Encrypted:', encrypted)
const decrypted = decrypt64(encrypted, hexKey)
console.log('Decrypted:', decrypted)
```
# API
### `encrypt64(text: string, hexKey: string): string`
- `text`: Plain text to encrypt.
- `hexKey`: Hexadecimal key. Must be 16 bytes (32 hex characters).
- Returns: Encrypted text as Base64.
### `decrypt64(base64Text: string, hexKey: string): string`
- `base64Text`: Encrypted text in Base64.
- `hexKey`: Hexadecimal key (same one used for encryption).
- Returns: Decrypted plain text.
# Technical details
- Algorithm: Twofish in ECB mode.
- Block size: 16 bytes.
- Padding: Space padding (`0x20`), same as used in GeneXus.
- Encoding: Base64.
# Compatibility
ā Compatible with values generated by GeneXus `Encrypt64()` and `Decrypt64()` functions.