Skip to content

Instantly share code, notes, and snippets.

View xgeek-net's full-sized avatar

Xiaoan Lin xgeek-net

View GitHub Profile
var crypto = require("crypto");
var uncipheredText = 'password123';
var secretkey ='your_secret_key';
// Encrypte
var cipher = crypto.createCipher('aes192', secretkey);
cipher.update(uncipheredText);
var cipheredText = cipher.final('base64');
console.log('Encrypted String :' + cipheredText);
crypto.js:323
var ret = this._binding.final();
^
TypeError: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length
at Decipher.Cipher.final (crypto.js:323:27)
at Object.<anonymous> (/home/ubuntu/workspace/app.js:75:22)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
var crypto = require("crypto");
var uncipheredText = 'password123';
var secretkey ='your_secret_key';
var cipher = crypto.createCipheriv('rc4', secretkey , '');
var crypt = cipher.update(uncipheredText, 'utf8', 'base64');
crypt += cipher.final('base64');
console.log('Encrypted String :' + crypt );
var decipher = crypto.createDecipheriv('rc4',secretkey , '');
Encrypted String :5gtIYSXKAyI+oSQ=
Decrypted String :password123
StaticResource sr = [SELECT Id, Body FROM StaticResource WHERE Name = 'MyJsonFile' LIMIT 1];
String body = sr.Body.toString();
System.assertEquals(body, '{"key1":"value1","key2":"value2"}');
StaticResource sr = [SELECT Id,NamespacePrefix,SystemModstamp FROM StaticResource WHERE Name = 'MyJsonFile' LIMIT 1];
String prefix = sr.NamespacePrefix;
if( String.isEmpty(prefix) ) {
prefix = '';
} else {
//If has NamespacePrefix
prefix += '__';
}
String srPath = '/resource/' + sr.SystemModstamp.getTime() + '/' + prefix + 'MyJsonFile';
PageReference pg = new PageReference( srPath );
StaticResource sr = [SELECT Id,NamespacePrefix,SystemModstamp FROM StaticResource WHERE Name = 'JsonZip' LIMIT 1];
String prefix = sr.NamespacePrefix;
if( String.isEmpty(prefix) ) {
prefix = '';
} else {
//If has NamespacePrefix
prefix += '__';
}
//Get the path of MyJsonFile.json file in Zip static resource
String srPath = '/resource/' + sr.SystemModstamp.getTime() + '/' + prefix + 'JsonZip/MyJsonFile.json';
<apex:includeScript value="{!$Resource.MyJavascriptFile}"/>
<apex:stylesheet value="{!$Resource.styles}"/>
<apex:includeScript value="{!URLFOR($Resource.LibraryZip, '/subdir/MyJavascriptFile.js')}"/>
<apex:stylesheet value="{!URLFOR($Resource.StyleSheetZip, 'styles.css')}"/>
{!REQUIRESCRIPT('/resource/' & LEFT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT(NOW()),':',''),'-',''),' ',''),10) & '000/MyJavascriptFile')}