encryption of .mat files
87 views (last 30 days)
Show older comments
*hello , i have stored the data of my application in .mat file , i edit and change the values of the variables throw my application , i don't want the other user to see the name of variables or the values , any suggested function or a way to encrypt the file ??
Thanks ALL*
0 Comments
Accepted Answer
Jan
on 18 Jul 2012
Edited: Jan
on 18 Jul 2012
You can implement a string encryption method by your own. Using Java you need 3 or 4 lines of code only. Unfortuantely the export laws do not allow to publish the code on a server located in the USA, because evil countries could use it to encrypt their evil data also.
But if you ask your favourite search engine for "MATLAB AES encryption", your are still successful, I think. If you are a citizen of an evil country, please do not ask a search engine. (Any additional details of my personal opinion about the US export restrictions would be off-topic.)
Then you have the standard problem, that the encryption key must be stored reliably also. Never store the password in clear text, even not in P-coded files, otherwise the decryption gets near to trivial and a dull ROT13 method would offer the same level of security.
Another problem appears, when you need to process MAT-files: You can write the MAT file in clear text, encrypt it and ship it to the users. But then you cannot load the file directly. You have to decrypt the file at first and write it to the harddisk before load can import the data. But then you need a very sophisticated method to remove the clear-text data from the disk afterwards. I'm convinced, that you cannot reach a 95% security level by this way.
You find tools to "serialize" objects in the FEX (use this term to search there). This means, that e.g. a struct can be converted to a byte stream, which can be encrypted easily. Then the decryption can happen in the memory as well as the "deserialization". In consequence the hard disk remains clean and the clear text data can only be found using a memory dump. When the password is kept securely, this means a security level of 99% (in arbitrary units...).
3 Comments
Matt Kindig
on 18 Jul 2012
An SQL database suffers the same problem as any other password-protection-- namely, if you can crack the password, you can access the data in the database. Obviously different SQL databases have different security approaches, and I don't know enough about them to offer anything further.
If the software that you have found to do the encryption/decryption can be operated from the Windows/Linux command line, you can access it using Matlab's system() command. You should then be able to run your software from within your .m file.
Walter Roberson
on 18 Jul 2012
Be cautious, though: if the software takes the encryption key on the command line, then someone monitoring the processes will be able to see the encryption key when you use system() or dos() or unix().
If you store the password in a file and redirect reading of the key from the file, then you have to ensure that the file is never readable by the user, which is tricky in MS Windows (and requires care and experience in Unix)
So you need SSL. Or need to use pipes.
Perhaps you should consider using your own binary format instead of .mat files.
More Answers (4)
Matt Kindig
on 18 Jul 2012
Edited: Matt Kindig
on 18 Jul 2012
Hi Khaled,
This hasn't gotten any bites yet, so I thought I'd take a stab at it, although I am not an encryption expert by any means.
What access do you want the "other user" to have to your data? As I understand it, you basically want to encrypt your file such that someone else cannot open and read your data. I'm not sure how you'll be able to do that in a *.mat file-- if you use Matlab to save the data in MAT format, the file will be written in such a way that it can be opened with Matlab, as that is the purpose of the file format. I don't believe that Matlab has an equivalent of Excel's "Protect Workbook" or similar. You can encrypt m-files such that they can be executed without revealing the source code (using the 'pcode' function), but that is obviously something different than you want.
If you want to store your data in a format that is available for reading only for yourself (or a limited number of people), you are probably better off writing to a binary file and then using one of a number of standard encryption codes. A quick search of the File Exchange indicates a few encryption functions--Google I'm sure has countless more. How secure do you need the encryption?
Matt
2 Comments
per isakson
on 18 Jul 2012
Edited: per isakson
on 18 Jul 2012
Matlab documentation:
New MAT-File Format Based on HDF5
In Version 7.3 (R2006b), you can save MAT-files in a format based on HDF5.
The v7.3 mat-file is documented and can be inspected with the hdf5-tools:
>> h5disp( 'mk.mat')
HDF5 mk.mat
Group '/'
Group '/#refs#'
Dataset 'a'
....
HDF5 is open and well supported.
In the "The Data Transfer Pipeline" of HDF5 it is possible to include your own code for encryption and decryption (and more common compression).
Thus, it should be doable - maybe.
2 Comments
per isakson
on 18 Jul 2012
Edited: per isakson
on 19 Jul 2012
I picked up the info above from reading the documentation and hdf-forum. I cannot add much. Bad news:
- the size of the "v7.3 file" is much larger than the compressed default file
- might work for values but maybe not for names.
If you are serious about it why not ask tech-support.
David Leffingwell
on 12 Jun 2023
If you are using the MATLAB Compiler, you can use the -s option to encrypt your data (e.g. MAT files) in addition to your M files. See here.
0 Comments
See Also
Categories
Find more on MATLAB Compiler in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!