Hello @JesterOC
You’re correct - Backendless does not provide a built-in Backendless.CryptoUtils
or Backendless.Crypto
object for cryptographic operations in custom code blocks (Cloud Code, API Services, or Event Handlers). That’s why you’re seeing the Cannot read properties of undefined (reading ‘SHA256’)
error.
- Try to use JavaScript Crypto API:
Documentation:
async function generateLicenseKey(cleanEmail, secret) {
const encoder = new TextEncoder();
const data = encoder.encode(cleanEmail + secret);
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
const license = hashHex.substring(0, 20).toUpperCase();
return license;
}
const license = await generateLicenseKey(cleanEmail, secret);
- Node.js crypto:
Documentation:
- Node.js Crypto module
- crypto.createHash()
- Hash.update()
- Hash.digest()
- Node.js official examples
- W3Schools Node.js Crypto
const crypto = require('crypto');
function generateLicenseKey(cleanEmail, secret) {
const raw = cleanEmail + secret;
const hash = crypto.createHash('sha256').update(raw).digest('hex');
const license = hash.substring(0, 20).toUpperCase();
return license;
}
Useful link:
Encrypting data
Regards,
Volodymyr