I am however, having problems setting up my src/declarations.d.ts file. I do not have a src folder or a declarations.d.ts file in my project.
Do you know if I should create one? If so, where should I place it in my folder structure? Id there anything else that needs to know about the src/declarations.d.ts file in order to register it?
After adding src/declarations.d.ts to the root of my project, I get:
ERROR in ./app/pages/service/personService.ts
(2,21): error TS2307: Cannot find module 'jsencrypt'.
Iām not sure, but maybe you use an old version of ionic framework with new version of ionic CLI (framework and CLI canāt work on different version. Latest CLI (2.1.4) work with ionic 2.0.0-rc0 and higher).
You can check your version by ionic info in terminal in root folder of your project. If framework version lover than 2.0.0-rc0 you need to update your project and fix all breaking changes.
Also you need local typescript 2+ in your project.
But I am scared if I try upgrade to the latest version2.0.0-rc.2 (2016-11-03), other things in my app will break. So I will look for another encryption tool.
I donāt want this to sound overly harsh, but if you are intending to distribute this app to anybody (i.e. if youāre not just using it as a personal learning experience), please please have the design done or at least audited by somebody who understands cryptographic protocols.
You do not want to be using naked RSA encryption for messages. You need to be using a padding scheme and key wrapping like OAEP. Designing cryptographic protocols is extremely hard, and even experts who know far more than either you or I make mistakes doing it. Donāt do it yourself. Use standards like JWE.
Itās not harsh, itās constructive criticism . Thank you for the advise.
Even though my requirements may appear simple to me (i.e. I am trying to hide the users password), as you are saying it is far more complex.
I donāt have much knowledge of secure systems . I think I need to do some more research and reading to try and understand. Unfortunately I donāt have access to a person who is knowledgeable in this area.
I tried to use https://github.com/square/js-jose, in order to use JWE, but had problems trying to import it into Ionic2. I think I will try again to make use of it.
Question
Is the main problem with using naked RSA encryption that the key is just sitting in the code exposed? That means anyone can access it to decrypt the ciphertext?
That is one problem. Whatever encryption algorithm you choose, storing hardcoded keys is a fatal flaw. Another is that RSA itself is not a suitable algorithm for directly encrypting messages. See here or other resources about padding.
I am committed to making the square js-jose library a best practice choice for ionic developers.
Probably, but itās hard to say more without more information about the workflow. Who is doing the encrypting and where, and who should be able to decrypt it and where? Do you want the server administrator to be able to read things, or do you specifically want that to be impossible?
Users will be presented a list of āfilesā, in which when they tap on that list item, it will download an encrypted file from an Amazon S3 bucket (AES256 preferred).
Once the file is decrypted, letās say itās an mp4 file, that mp4 file would then be loaded into a <video> tag so that the user could then watch the video. This exact thing will applicable to any file types (pdf, mp3, docx, etc.)
That is pretty much it. There is actually no need to upload an encrypted file, only decrypt one that is downloaded from an Amazon S3 bucket.
Any thoughts? I havenāt seen a whole lot on this. Could Crypto-Js be a viable solution inside of an Ionic 2 app?
What is the purpose of the encryption? DRM so that the users must somehow acquire the key separately? In general, you could use AES-GCM (my preference) or AES-CBC. JWE supports direct encryption mode, where the key must be passed separately. Your keyserver could have a list of file URLs and the AES keys used to encrypt them. It could dispense them to authenticated users. The client app could then use the key to decode the JWE it downloaded from S3. I think js-jose could handle this in fairly straightforward fashion, and you could use it (or the sister Golang implementation) to create the encrypted documents on the server side. I would definitely recommend using JWE over rolling your own encrypted packaging system; it has gone through extensive peer review.
Ah this is very good. Thankyou for that. There were some new terms I needed to research. So with this being said, it looks like js-jose would be a good option. The next big question isā¦since there doesnāt seem to be much documentation on how to import it into Angular 2, do you have any idea of the steps that would need to happen in order to be able to use it in an Ionic 2 app?