3

I have a XML file stored on the SDCard. I need to perform encryption and decryption on the complete file as a unit.

I have seen that Spongy Castle is a good library for the Encryption and Decryption for android. But, I could not find any cipher class to encrypt and decrypt the file as a single unit. I would be really grateful if anyone could provide some further assistance on this. Any sample code will be of great help.

Masoud Mokhtari
  • 2,390
  • 1
  • 17
  • 45
Rahul Kalidindi
  • 4,666
  • 14
  • 56
  • 92
  • Are you sure you're not talking about Bouncy Castle? Could you please expand on your requirements? Do you need symmetric or assymetric cryptography? Where are the keys coming from? Of the standard information security terms of "confidentiality", "authentication", and "integrity", do you need all three, or some subset? – Asim Ihsan Sep 07 '11 at 11:11
  • I have read that there are some drawbaks of standard Bounty Castle provided in Android. So, I am inclined to use Spongy Castle lib. The keys are part of the project saved in the assets folder. – Rahul Kalidindi Sep 08 '11 at 04:00
  • Spongy Castle is a simple repackage of Bouncy Castle: https://github.com/rtyley/spongycastle#readme - so any tutorials for Bouncy Castle will also apply to Spongy Castle. There is a very simple demo of it here https://github.com/rtyley/spongycastle-eclipse#readme - it just demonstrates reading some keys, it's not actually decrypting/encrypting any data. – Roberto Tyley Sep 16 '11 at 11:13

1 Answers1

3

Could you please take a look at previous questions that cover cryptography on Android and let us know if they answer your question? If not, could you please expand on your requirements, in particular explaining in detail why you need to encrypt this particular XML file, and where you expect the keys to be coming from?

Android comes with an old version of Bouncy Castle; you probably want to include an up-to-date version of Bouncy Caslte if you need more cryptographic algorithms and modes.

And please, please, please, before you implement or even consider future use of cryptography, read the following article: Cryptographic Right Answers. If you don't understand any of the concepts in the article please consider consulting some references, which I'm happy to provide in a different SO question.

Community
  • 1
  • 1
Asim Ihsan
  • 1,501
  • 8
  • 18
  • I have looked for answers to encrypt the files but there are only answers regarding encrypting and decrypting strings. Can u plz let me know how to encrypt and decrypt a file using the SpongyCastle lib. – Rahul Kalidindi Sep 08 '11 at 04:02
  • Why can't you read in the file as a byte array and then encrypt it as if it were a string? If you don't think the file will fit in memory you can read it in chunk by chunk surely? But I understand now - you want specific examples of using SpongyCastle, OK. – Asim Ihsan Sep 08 '11 at 09:32