Please note that there is no general best way to secure credentials because this security measure is very context-dependent. That being said, MATLAB Compiler has capabilities to encrypt obfuscated information in the form of P-files. The following procedure is one way to package credentials with an application, although note that MathWorks makes no guarantees as to the security of such an application.
- Hardcode the credentials into an M-file.
- Use the 'pcode' function to convert the M-file into a P-file. This obfuscates the credentials.
- When MATLAB Compiler creates the application, all P-files and M-files are encrypted.
The end result is that your credentials are both obfuscated and encrypted. However, note that our encryption protocol does not have an "Orange Book" classification. No security protocol or encryption algorithm is ever completely secure. It is possible that a determined attacker could find a way to read the contents of MATLAB files in a deployed application. We expect this would be quite difficult to do, but we neither claim it is impossible, nor can we quantify the level of difficulty.
Note that you may need to include the P-files in your application manually, as the Dependency Analyzer for MATLAB Compiler may not detect all the necessary P-files. For more information, please see the following documentation page:
Best Answer