java - BouncyCastle openPGP encrypt byte[] array as csv file -
i have gotten code able load in public key, , encrypt byte[] array public key else has provided. however, when decrypt file, doesn't have .csv extension. can open in excel , looks csv once open it, file doesn't have extension associated it, have weirdly open in excel.
i've attached code below , couldn't figure out modify when decrypt using kleopatra, shows .csv extension. tried change output stream .csv .gpg file, throws error saying not determine whether openpgp signature. think have ldata.open() method, options can put there pgpliteraldata.text, binary, , utf8. maybe has adding signature file?
btw, code below, public key loaded variable called pubkey.
byte[] bytesarray = getaccesschannels(customeralias); outputstream out = new fileoutputstream("/path/to/file/edata.gpg"); security.addprovider(new bouncycastleprovider()); bytearrayoutputstream bout = new bytearrayoutputstream(); pgpcompresseddatagenerator comdata = new pgpcompresseddatagenerator(pgpcompresseddatagenerator.zip); outputstream cos = comdata.open(bout); // open final destination pgpliteraldatagenerator ldata = new pgpliteraldatagenerator(); outputstream pout = ldata.open(cos, pgpliteraldata.text, "report.csv", bytesarray.length, new date()); pout.write(bytesarray); ldata.close(); comdata.close(); pgpencrypteddatagenerator cpk = new pgpencrypteddatagenerator(new bcpgpdataencryptorbuilder(symmetrickeyalgorithmtags.aes_256).setsecurerandom(new securerandom())); cpk.addmethod(new bcpublickeykeyencryptionmethodgenerator(pubkey)); byte[] bytes = bout.tobytearray(); outputstream cout = cpk.open(out, bytes.length); cout.write(bytes); // obtain actual bytes compressed stream cout.close();
nevermind, needed change file extension edata.csv.gpg...this took me whole 2 days

Comments
Post a Comment