java - When and why decorate OutputStream with ArmoredOutputStream when using BouncyCastle -
i'm pretty new bouncycastle , pgp. i've seen many articles , samples on internet. every encryption sample contains code snipped below
if (armor) out = new armoredoutputstream(out);
it seems local test passed both armor , none-armor. googled around found few useful , javadoc of armoredoutputstream shows basic output stream.
so what's difference , when utilize it?
complete code sample:
public static void encryptfile(string decryptedfilepath, string encryptedfilepath, string enckeypath, boolean armor, boolean withintegritycheck) throws exception{ outputstream out = new fileoutputstream(encryptedfilepath); fileinputstream pubkey = new fileinputstream(enckeypath); pgppublickey enckey = readpublickeyfromcollection2(pubkey); security.addprovider(new bouncycastleprovider()); if (armor) out = new armoredoutputstream(out); // init encrypted info generator pgpencrypteddatagenerator encrypteddatagenerator = new pgpencrypteddatagenerator(pgpencrypteddata.cast5, withintegritycheck, new securerandom(),"bc"); encrypteddatagenerator.addmethod(enckey); outputstream encryptedout = encrypteddatagenerator.open(out, new byte[buffer_size]); // init compression pgpcompresseddatagenerator compresseddatagenerator = new pgpcompresseddatagenerator(pgpcompresseddata.zip); outputstream compressedout = compresseddatagenerator.open(encryptedout); pgpliteraldatagenerator literaldatagenerator = new pgpliteraldatagenerator(); outputstream literalout = literaldatagenerator.open(compressedout, pgpliteraldata.binary, decryptedfilepath, new date(), new byte[buffer_size]); fileinputstream inputfilestream = new fileinputstream(decryptedfilepath); byte[] buf = new byte[buffer_size]; int len; while((len = inputfilestream.read(buf))>0){ literalout.write(buf,0,len); } literalout.close(); literaldatagenerator.close(); compressedout.close(); compresseddatagenerator.close(); encryptedout.close(); encrypteddatagenerator.close(); inputfilestream.close(); out.close(); } }
armoredoutputstream
uses encoding similar base64, binary non-printable bytes converted text friendly. you'd if wanted send info on email, or post on site, or other text medium.
it doesn't create difference in terms of security. there a slight expansion of message size though. selection depends on want output.
java encryption bouncycastle pgp openpgp
No comments:
Post a Comment