loadEncryptedObject; cant manage to Un-encrypt file data
-
Hi all.
Merry Christmas! Hope Santas generous this year... :)Im trying to encrypt/decrypt data thats inside a file.
Encryption works, it encrypts upon pressing the "Encrypt"Button, however i cant manage to un-encrypt/view the data. Its suppose to check/decrypt on startUp but its not happening..Putting "decryptOnLoad()" inside a onButtonControl statement and calling it, doesnt make any difference.
Where am i going wrong with the code?
Thanks very much!
const var Encrypt = Content.getComponent("Encrypt"); //Encrypt file on button click inline function onEncryptControl(component, value) { local SystemId = FileSystem.getSystemId(); if(value) { local UserPIN = "1234"; //Browse to the file local FileDirectory = FileSystem.getFolder(FileSystem.UserPresets).getParentDirectory(); FileDirectory.getChildFile("file.js").writeEncryptedObject(UserPIN, SystemId); } }; Content.getComponent("Encrypt").setControlCallback(onEncryptControl); //Decrypt on startup const var Decrypt = Content.getComponent("Decrypt"); inline function decryptOnLoad() { local UserPIN = "1234"; //Get encrypted file/object local FileDirectory = FileSystem.getFolder(FileSystem.UserPresets).getParentDirectory(); //Decrypt FileDirectory.getChildFile("file.js").loadEncryptedObject(UserPIN); // Load contents of the encrypted object local pData = Engine.loadFromJSON(FileDirectory); }; // Execute on startup decryptOnLoad(); // works inside onButton??? ...... Nope.. inline function onDecryptControl(component, value) { if(value) { decryptOnLoad(); } }; Content.getComponent("Decrypt").setControlCallback(onDecryptControl);
-
@ten7kur - er its a function not an inline function isnt it? - have you tried this:
function decryptOnLoad() { local UserPIN = "1234"; //Get encrypted file/object local FileDirectory = FileSystem.getFolder(FileSystem.UserPresets).getParentDirectory(); //Decrypt FileDirectory.getChildFile("file.js").loadEncryptedObject(UserPIN); // Load contents of the encrypted object local pData = Engine.loadFromJSON(FileDirectory); };
-
File.writeEncryptedObject(var jsonData, String key)
You got the argument order reversed, so you end up encrypting the key with the data you want as key. I might add a check that you don't pass a JSON object as key to prevent this in the future...
-
@Lindon ? The code you pasted is eaxctly the same as mine.
@Christoph-Hart
I was using it that way because of this--> Getting todays date in HISE post. My understanding was that it was encrypting the data with a password AND the MachineID. Perhaps i misused/misunderstood the example..Never the less, i made the changes but the file doesnt seem to be getting encrypted /edited at all.
Im mis-printing something....
The new Code;const var Encrypt = Content.getComponent("Encrypt"); //Encrypt file on button click inline function onEncryptControl(component, value) { local SystemId = FileSystem.getSystemId(); if(value) { local UserPIN = "1234"; //Browse to the file local FileDirectory = FileSystem.getFolder(FileSystem.UserPresets).getParentDirectory(); FileDirectory.getChildFile("file.js"); //Encrypt local FileEncrypt = FileDirectory.writeEncryptedObject(FileDirectory, UserPIN); } }; Content.getComponent("Encrypt").setControlCallback(onEncryptControl); //Decrypt on startup const var Decrypt = Content.getComponent("Decrypt"); inline function decryptOnLoad() { local UserPIN = "1234"; //Get encrypted file/object local FileDirectory = FileSystem.getFolder(FileSystem.UserPresets).getParentDirectory(); FileDirectory.getChildFile("file.js"); //Decrypt local FileDecrypt = FileDirectory.loadEncryptedObject(UserPIN); // Load contents of the encrypted object local pData = Engine.loadFromJSON(FileDirectory); }; // Execute on startup decryptOnLoad();
-
HiseSnippet 1062.3ocsVstaaaCElxwZXVcsXEXO.B9Wx.Y1xsocC0nnY9VgwZRLlSK19UAMEcLajHEnnRpQgA1i7dC1NjRxR1wsK0.0AH1mq76bgmCmJEDZRhPhrZb4pXJx5GrmshqVNXIlwQSFhrdj8Y3DEU5lwp+pXbRBM.YYczq0LrZTGY97OupONDyIzRVHz6DLB8MrHlpj6zS+cVX3Xb.8RVTEsO4zIDAefHTjB34HaeTLlbM9J54XsZ0rQVe2n.lRHmovJZBnSeQvpYKE2xyz+crD17PplnKZF3nL1nAKYgASKh0DDxp9zxH+nrH+mrOiEv1vuLC7iFAtkVTMGXUaaHUeKH08yAowhv.sC9LvypB7pmAuGaOiHYwpRIZr8.6Ibn3r.Co8pvJSWTs+pt8.AnAW0NBeMcrDH1Xg2y88O18Y99s58PG8e2fktAXE9RwHNQtJV49R2O0bkHMl07EcO107SQyW3utWtxTiZzfgfUFm3zoSgsKXgTWA2cdpRAeQBYjqcX7PFm5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