This blog post was created with AI assistance to help developers understand Uniface's cryptographic capabilities.
π€ What is $decode?
The $decode
function in Uniface 10.4 is a powerful tool for handling encrypted and encoded data. Think of it as your digital key π for unlocking three main types of data:
- Encrypted data - Data that was scrambled using encryption algorithms
- Encoded data - Data that was converted using encoding schemes like Base64
- Digital signatures - Verification of message authenticity
π Basic Syntax
The function has two main formats:
For Decryption/Decoding:
$decode(Algorithm, Source, Key, Mode, InitializationVector)
For Signature Verification:
$decode(Algorithm, Source, Key, Signature)
π§ Supported Algorithms
π Encoding Algorithms (Simple Data Conversion)
- BASE64 - Most common web encoding
- HEX - Hexadecimal encoding
- URL - URL-safe encoding
- BASE64URL - URL-safe Base64
π‘οΈ Block Ciphers (Strong Encryption)
- AES - Advanced Encryption Standard (recommended)
- DES/TDES - Older standards (less secure)
- BLOWFISH/TWOFISH - Alternative encryption methods
π RSA Algorithms (Public Key Cryptography)
RSA algorithms use key pairs (public/private keys). Examples include:
- RSAES_OAEP_SHA256 - Modern RSA encryption
- RSASSA_PSS_SHA256 - RSA digital signatures
π‘ Practical Examples
Example 1: Simple Base64 Decoding
vDecoded = $decode("BASE64", "SGVsbG8gV29ybGQ=")
; Result: "Hello World"
Example 2: AES Encryption/Decryption
; First encrypt some data
vEncrypted = $encode("AES", "Secret Message", "MySecretKey12345", "CBC", vIV)
; Then decrypt it back
vDecrypted = $decode("AES", vEncrypted, "MySecretKey12345", "CBC", vIV)
vMessage = $encode("USTRING", vDecrypted) ; Convert to string
Example 3: Digital Signature Verification
vIsValid = $decode("RSASSA_PSS_SHA256", vMessage, vPublicKey, vSignature)
; Returns 1 (true) if signature is valid, 0 (false) if not
β οΈ Common Errors and Solutions
Error Code | Problem | Solution |
---|---|---|
-1780 | Algorithm not found | Check algorithm spelling π |
-1786 | Invalid key length | Use correct key size (AES: 16/24/32 bytes) π |
-1787 | Invalid HEX format | Ensure data contains only 0-9, A-F characters π€ |
-1788 | Invalid BASE64 format | Check for proper Base64 padding (=) π |
π― Best Practices
- Always check $procerror after calling $decode π
- Use AES over DES for new applications π‘οΈ
- Store keys securely - never hardcode them π«
- Use proper IV (Initialization Vector) for CBC mode π²
- Convert raw data to string when needed using USTRING π
π Working with Raw Data
Important: $decode
returns data in Uniface's raw data type. This can contain null bytes (0x00) that would break regular strings. To convert raw data back to a readable string:
vRawData = $decode("BASE64", vEncodedData)
vStringData = $encode("USTRING", vRawData) ; Convert to string
π Real-World Use Cases
- API Integration - Decoding Base64 responses from web services π
- File Processing - Decrypting uploaded files π
- Database Security - Decrypting sensitive data fields ποΈ
- Authentication - Verifying JWT token signatures π«
π Conclusion
The $decode
function is a versatile tool in Uniface 10.4 that handles various cryptographic operations. Whether you're working with simple Base64 data or complex RSA encryption, understanding this function opens up many possibilities for secure application development. Remember to always validate your inputs and handle errors properly! πͺ
Happy coding! π¨βπ»π©βπ»
Top comments (0)