Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Store and use encrypted data

Subject: Store and use encrypted data

From: Luca Cerone

Date: 1 Feb, 2010 16:31:06

Message: 1 of 19

Hi everybody,
I'd like to setup my Matlab so that I can be able to send email
to a recipient list of people using my Yahoo account.
I'd like to avoid my username and password to be visible (at least the password),
and also the people addresses I want the email to be sent.
Is there an easy way to store this informations in an encrypted file to be used
by my Matlab functions?
Thank you very much in advance,
Cheers, -Luca

Subject: Store and use encrypted data

From: Steven Lord

Date: 1 Feb, 2010 18:12:37

Message: 2 of 19


"Luca Cerone" <luca_cerone#_remove_this#@yahoo.it> wrote in message
news:hk6vka$2q4$1@fred.mathworks.com...
> Hi everybody,
> I'd like to setup my Matlab so that I can be able to send email
> to a recipient list of people using my Yahoo account.
> I'd like to avoid my username and password to be visible (at least the
> password),
> and also the people addresses I want the email to be sent.
> Is there an easy way to store this informations in an encrypted file to be
> used
> by my Matlab functions?

Write a small function to send the email and then PCODE that function.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: Store and use encrypted data

From: us

Date: 1 Feb, 2010 18:28:05

Message: 3 of 19

"Luca Cerone" <luca_cerone#_remove_this#@yahoo.it> wrote in message <hk6vka$2q4$1@fred.mathworks.com>...
> Hi everybody,
> I'd like to setup my Matlab so that I can be able to send email
> to a recipient list of people using my Yahoo account.
> I'd like to avoid my username and password to be visible (at least the password),
> and also the people addresses I want the email to be sent.
> Is there an easy way to store this informations in an encrypted file to be used
> by my Matlab functions?
> Thank you very much in advance,
> Cheers, -Luca

a hint:
- read your name/password from a p-coded M-file...

us

Subject: Store and use encrypted data

From: Luca Cerone

Date: 1 Feb, 2010 18:35:26

Message: 4 of 19

Thanks a lot for the advices,
pcode seems to help, but actually, which kind of encryption does it perform?
I mean apart that the code is not actually readable, which is the level of protection?

Thanks a lot in advance!
Cheers, -Luca

Subject: Store and use encrypted data

From: us

Date: 1 Feb, 2010 18:42:06

Message: 5 of 19

"Luca Cerone" <luca_cerone#_remove_this#@yahoo.it> wrote in message <hk76te$h5h$1@fred.mathworks.com>...
> Thanks a lot for the advices,
> pcode seems to help, but actually, which kind of encryption does it perform?
> I mean apart that the code is not actually readable, which is the level of protection?
>
> Thanks a lot in advance!
> Cheers, -Luca

well...
at least to the point where zillions of very keen ML cognoscentes have tried to break the code for decades - without success...
don't worry...

:-)
us

Subject: Store and use encrypted data

From: Walter Roberson

Date: 1 Feb, 2010 19:06:56

Message: 6 of 19

Luca Cerone wrote:
> Thanks a lot for the advices,
> pcode seems to help, but actually, which kind of encryption does it
> perform?
> I mean apart that the code is not actually readable, which is the level
> of protection?

pcode only promises parsing, not encryption. You get AES encryption if you use
the matlab compiler.

Subject: Store and use encrypted data

From: Jan Simon

Date: 2 Feb, 2010 00:44:06

Message: 7 of 19

Dear Luca!

> pcode seems to help, but actually, which kind of encryption does it perform?
> I mean apart that the code is not actually readable, which is the level of protection?

If you run your P-coded function, it will call other functions, e.g. to send the data. These other functions can be easily shadowed by M-files in the same directory. Therefore it is easy to listen to all output of your function and the secret password is not protected in a P-file.

A nice example for a trial to protect information in a P-file is Matt Fig's pass_protect in the FEX. Nevertheless, it can be broken in a minute.

Kind regards, Jan

Subject: Store and use encrypted data

From: Luca Cerone

Date: 2 Feb, 2010 10:36:05

Message: 8 of 19

Thanks for answers and help...
actually seems that pcode doesn't really help, and I think there might be some
issues even if I would use a compiled function:
the main problem is that settinge for the email should be set up like:
setpref('Internet','SMTP_Username',myusername)...
but if you do so (even in a compiled function), these data are easily retrieved
using getpref('Internet')...
So I was thinking to modify the sendmail.m function so that after having retrieved
preferences it would use a private key to decrypt the values...
but actually am not so sure that it would work....

Any suggestion about it?
Cheers, -Luca

Subject: Store and use encrypted data

From: Jan Simon

Date: 2 Feb, 2010 19:24:05

Message: 9 of 19

Dear Luca!

There are some AES encryption utilies on the FEX, so you can store encrypted strings as preferences. But as far as I understand, you send the password in clear text through the internet? Then there is no real reason to keep them secret locally...

Kind regards, Jan

Subject: Store and use encrypted data

From: John

Date: 23 Dec, 2010 10:58:04

Message: 10 of 19

"Jan Simon" wrote in message <hk9u4l$m9e$1@fred.mathworks.com>...
> Dear Luca!
>
> There are some AES encryption utilies on the FEX, so you can store encrypted strings as preferences. But as far as I understand, you send the password in clear text through the internet? Then there is no real reason to keep them secret locally...
>
> Kind regards, Jan

Hi Jan,

Can I use AES encryption for "struct" variables too? I have tried Michael Kleder's routine but it accepts only matrices.

Thanks.

Subject: Store and use encrypted data

From: Jan Simon

Date: 23 Dec, 2010 12:02:04

Message: 11 of 19

Dear John,

> Can I use AES encryption for "struct" variables too? I have tried Michael Kleder's routine but it accepts only matrices.

Please use a new thread for a new question.

You can either store the struct as a MAT file at first using SAVE.
Or try Tim's SERIALIZE:
  http://www.mathworks.com/matlabcentral/fileexchange/29457
before encrypting.

Kind regards, Jan

Subject: Store and use encrypted data

From: John

Date: 23 Dec, 2010 15:41:05

Message: 12 of 19

"Jan Simon" wrote in message <ievdns$ljk$1@fred.mathworks.com>...
> Dear John,
>
> > Can I use AES encryption for "struct" variables too? I have tried Michael Kleder's routine but it accepts only matrices.
>
> Please use a new thread for a new question.
>
> You can either store the struct as a MAT file at first using SAVE.
> Or try Tim's SERIALIZE:
> http://www.mathworks.com/matlabcentral/fileexchange/29457
> before encrypting.
>
> Kind regards, Jan

Thanks for your answer Jan.

It is not an old thread and I wanted to ask about same topic. So I believe no need to create a new thread for my question.

So I do the following.

I save the struct as *.mat file and read the mat file as binary. And then encrypt the file and save back to drive again. But how can I convert the binary file to struct again after I open and decrypt the encrypted file.

Code:

save(fileName, '-mat','-struct', 'someStructs');

fid = fopen(fileName, 'rb');

data = fread(FID, 'uint8=>uint8');

encryptedData = aescrypt(dzip(data ),key);

I don’t know how to convert "uint8" "encryptedData" back to struct variable.

Thanks.

Subject: Store and use encrypted data

From: Walter Roberson

Date: 23 Dec, 2010 16:34:17

Message: 13 of 19

On 23/12/10 9:41 AM, John wrote:

> So I do the following.
>
> I save the struct as *.mat file and read the mat file as binary. And
> then encrypt the file and save back to drive again. But how can I
> convert the binary file to struct again after I open and decrypt the
> encrypted file.
>
> Code:
>
> save(fileName, '-mat','-struct', 'someStructs');
>
> fid = fopen(fileName, 'rb');
>
> data = fread(FID, 'uint8=>uint8');
>
> encryptedData = aescrypt(dzip(data ),key);
>
> I don’t know how to convert "uint8" "encryptedData" back to struct
> variable.

The decrypted file is *not* a struct: the decrypted file is a complete
matlab .mat file.

Mathworks does not provide user-level tools for dealing with .mat files
in memory. I don't know what tools are available through mex.

Subject: Store and use encrypted data

From: John

Date: 24 Dec, 2010 12:28:04

Message: 14 of 19

Thanks Walter.

Then I made up an idea. First save the struct as *.mat file then compress the *.mat as protected "zip" file and delete the *.mat file. But as I can see, Matlab zip function doesn't offer password protection. Is there any way to do this?

Subject: Store and use encrypted data

From: Walter Roberson

Date: 24 Dec, 2010 16:40:46

Message: 15 of 19

On 24/12/10 6:28 AM, John wrote:

> Then I made up an idea. First save the struct as *.mat file then
> compress the *.mat as protected "zip" file and delete the *.mat file.
> But as I can see, Matlab zip function doesn't offer password protection.
> Is there any way to do this?

"Protected zip" files generally have password algorithms that are
breakable in fairly reasonable amounts of time. Some of them are
breakable within minutes. You would have to choose carefully to find one
that offered strong protection, and when you found it, it would not be a
"standard" password-protected zip file (but whatever it is might perhaps
offer a library with a callable interface. Or not.)

Subject: Store and use encrypted data

From: John

Date: 25 Dec, 2010 12:24:04

Message: 16 of 19

Actually new winzip offers 256 bit AES encryption so I don't think it takes minutes to break in. But anyway, Matlab doesn’t offer a function to create encrypted zip files.

I have a solution instead and it works fine with some limitations: Serializing as Jan suggested and then use AES encryption together with dzip (If dzip is not used, you get only first letters of the fields after decryption).

Encryption:
ct = aescrypt(dzip(serialize(your_struct)),key);

Decryption:
your_struct = deserialize(dunzip(aesdecrypt(ct,key)));

Serialize/Deserialize:
http://www.mathworks.com/matlabcentral/fileexchange/29457

Rapid AES data encryption and decryption:
http://www.mathworks.com/matlabcentral/fileexchange/8925-rapid-aes-data-encryption-and-decryption

Rapid lossless data compression of numerical or string variables:
http://www.mathworks.com/matlabcentral/fileexchange/8899

Limitations:
It doesn’t work if there is a logical array in struct.
There shouldn’t be more than 256 fields in struct.

Subject: Store and use encrypted data

From: Jeremy

Date: 18 Mar, 2011 18:01:07

Message: 17 of 19

Hi. Is anyone still following this thread? I'm trying to find the aescrypt function (by M. Kleder) that several of you have referred to. The function no longer appears to be available on the FEX. Is there a reason it would have been removed from the FEX? Does anyone still have it? Would you mind sending it to me? Thanks!

Subject: Store and use encrypted data

From: Think two, count blue.

Date: 18 Mar, 2011 21:25:22

Message: 18 of 19

On 11-03-18 01:01 PM, Jeremy wrote:
> Hi. Is anyone still following this thread? I'm trying to find the aescrypt
> function (by M. Kleder) that several of you have referred to. The function no
> longer appears to be available on the FEX. Is there a reason it would have
> been removed from the FEX? Does anyone still have it? Would you mind sending
> it to me? Thanks!

Just extract the code from the place you found it posted. That _is_ the code.

http://groups.google.com/group/comp.soft-sys.matlab/browse_thread/thread/b7e83c5062ef4e51/f33f7147a168d0ba?lnk=raot

Subject: Store and use encrypted data

From: Jeremy

Date: 18 Mar, 2011 21:41:05

Message: 19 of 19

Brain fart. Didn't pay very close attention on that google groups page. Thanks.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us