• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Encryption/decryption using java

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dear all,

i want to encrypt a .tar file or gzip file using java and again dycrypt and get th eoriginal file.
please provide me help on this with good encryption/decryption.

Thanks
rakesh
 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could read the file byte by byte and increase every value for an arbitrary number. It's not good encription, but it works

something like:


This code was written on the fly, to get you the idea ...
 
Rakesh Kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dear Martin Vanyavchich thankx for your support.
In my project actually i need more security for some files so it should made into .tar files and encrypt and then ftl to my local machine from server.
Then encrypt that file and gate the actual tar.

Cau please help me giving any link or any free library for this purpose.
Again thanks for your response ans idea.

Thanks
rakesh
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The standard Java API for encryption is called JCE, and it's part of the JRE. The SecurityFaq has some links to introductory material.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out Cipher, CipherInputStream and CipherOutputStream. The latter two are subclasses of FilterInputStream and FilterOutputStream respectively which means you can chain them. For example, for reading an encrypted gzip file:
Please note that the order is quite important:
- FileInputStream, being the actual source, needs to be the innermost InputStream
- since that file itself is encrypted, decrypting goes next with the CipherInputStream
- the unzipping finally follows

The writing code will be similar:
You can replace the outer stream (GZIPInputStream / GZIPOutputStream) with ZipInputStream / ZipOutputStream for regular zipping / unzipping, and with TarInputStream / TarOutputStream for using TAR to pack / unpack. For tar.gz or tgz files you can make the chain even one longer:
 
You know it is dark times when the trees riot. I think this tiny ad is their leader:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic