Reputation: 3783
Is anyway to save a .mat
file (contains database) as encrypted file. I want only my program (GUI) read these .mat
files, not other users by directly opening files in MATLAB.
This link may halp but I'm not familiar with this page definitions. Can you describe it with more details? : Serialize/Deserialize
Thanks.
Upvotes: 3
Views: 3095
Reputation: 71
Not that I have heard of, however there may be a way to protect it in a different way:
Due to lack of MWE, I came up with an example: I am assuming you know which variables you want to save. I have assumed here that variables A and B are to be saved. A is a double, B is a logical (different sizes). (cells need to be saved differently (cell by cell), let alone structs...!)
A=[1,2,3,4;5,6,7,8]; % your data (double) in your GUI
B=[0,1,1,0,1]==1; % your data (logical) in your GUI
pw='user2991243'; % make up a 'password' as variable in the GUI
% call this from your GUI function
function CreateHiddenData(A,B)
fid=fopen('hiddendata.m','w');
fprintf(fid, '%s\n', 'if strcmp(''user2991243'',pw)');
% for a double
str='A=[';
for k=1:size(A,1)
str=[str num2str(A(k,:)) ';'];
end
str=[str '];'];
fprintf(fid, '%s\n', str);
% for a logical
str='B=[';
for k=1:size(B,1)
str=[str num2str(B(k,:)) ';'];
end
str=[str ']==1;'];
fprintf(fid, '%s\n', str);
fprintf(fid, '%s\n', 'end');
fclose(fid);
pcode hiddendata
delete('hiddendata.m')
end
For your program, you can directly call the .p file, it will loads the variable(s) into the workspace. (Although this will overwrite all variables with the same name)
Upvotes: 3