How to decrypt a file in UNIX?

I have a file which contains encrypted data. Can anyone tell me how to decrypt the file?

You have not provided sufficient information for anybody to be able to help you. For example, do you know what encryption method was used to encrypt the file? Do you know what type of plaintext is in the file? ASCII, binary or what?

I have no idea about the type of encryption or type of text the file contains. We are extracting the file from sfdc,when we extract,we are getting encrypted data. The file content is-

Q2xhaW1OdW1iZXIsQ2xhaW1EZWFsVHlwZSxSZWplY3Rpb25SZWFzb24sRGVhbE51bWJlcixTYWxlc09yZGVyTnVtYmVyLEhQU2FsZXNPcmRlck51bWJlcixJbnZvaWNlRGF0ZSxJbnZvaWNlTnVtY
mVyLFNLVSxRdWFudGl0eSxTZXJpYWxOdW1iZXIsQmlsbFRvTmFtZSxFVXNlck5hbWUsQmlsbFRvQWRkcmVzczEsQmlsbFRvQWRkcmVzczIsQmlsbFRvQ2l0eSxCaWxsVG9TdGF0ZSxCaWxsVG9aaX
BDb2RlLFNoaXBUb05hbWUsU2hpcFRvQWRkcmVzczEsU2hpcFRvQWRkcmVzczIsU2hpcFRvQ2l0eSxTaGlwVG9TdGF0ZSxTaGlwVG9aaXBDb2RlLEVuZFVzZXJOYW1lLEVuZFVzZXJBZGRyZXNzMSx
FbmRVc2VyQWRkcmVzczIsRW5kVXNlckNpdHksRW5kVXNlclN0YXRlLEVuZFVzZXJaaXBDb2RlLEJhdGNoTnVtYmVyLENvbXBhbnlMb2NhdGlvbklELERpc3RyaWJ1dG9yTmFtZQ0KIkMxMjQ1MzIi
LCJWb2x1bWUgSFBOIFN3aXRjaGluZyBSb3V0aW5nIEFwcGxpY2F0aW9ucyBBY2Nlc3NvcmllcyBOQk8iLCIiLCJENzIxNzU4IiwiIiwiIiwiOC8xLzIwMTMgMTI6MDA6MDAgQU0iLCI0MDI1NjE0M
TEiLCJKOTcyN0EjQUJBIiwiMiIsIiIsIkNBTUVSQSBDT1JORVIgQ09OTkVDVElORyBQT0lOVCIsIkJBREdFUiBTSEVFVCBNRVRBTCIsIkdFIENPTU1FUkNJQUwgR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Q3ODAxIiwiIiwiIiwiOC8yLzIwMTMgM
TI6MDA6MDAgQU0iLCIzMjE3Mzc4MjEiLCJEOEU2NlVUI0FCQSIsIjExIiwiIiwiTkVUR0FJTiBURUNITk9MT0dJRVMgSU5DIiwiQ0VOVEVSUyBGT1IgWU9VVEggJiBGQU1JTElFUyIsIlBPIEJPWC
AyNTE5NzAiLCIiLCJMSVRUTEUgUk9DSyIsIkFSIiwiNzIyMjUxOTcwIiwiQ0VOVEVSUyBGT1IgWU9VVEggJiBGQU1JTElFUyIsIjY1MDEgVyAxMlRIIFNUIiwiIiwiTElUVExFIFJPQ0siLCJBUiI
sIjcyMjA0MTUxMSIsIkNFTlRFUlMgRk9SIFlPVVRIICYgRkFNSUxJRVMiLCI2NTAxIFcgMTJUSCBTVCIsIiIsIkxJVFRMRSBST0NLIiwiQVIiLCI3MjIwNDE1MTEiLCIyNDIyIiwiMTAwMjYyNDIi
LCJJbmdyYW0gTWljcm8gLSAxMDAyNjI0MiIsDQ==

Usually, for decryption, you need a key, a password or alike. If you don't, chances are low.

Your example does not show encrypted, but encoded data. In this case it is base64. Use commands like

openssl base64 -d <input >output

The openssl command is a little picky about the line length. You have to reformat the text, so that all but the last line are exactly 64 characters long.

I am not getting any data in the output file,its creating empty output file. Please help.

As I said, openssl is a little picky, every encoded line (except the last one) has to be 64 characters long.

Q2xhaW1OdW1iZXIsQ2xhaW1EZWFsVHlwZSxSZWplY3Rpb25SZWFzb24sRGVhbE51
bWJlcixTYWxlc09yZGVyTnVtYmVyLEhQU2FsZXNPcmRlck51bWJlcixJbnZvaWNl
RGF0ZSxJbnZvaWNlTnVtYmVyLFNLVSxRdWFudGl0eSxTZXJpYWxOdW1iZXIsQmls
bFRvTmFtZSxFVXNlck5hbWUsQmlsbFRvQWRkcmVzczEsQmlsbFRvQWRkcmVzczIs
QmlsbFRvQ2l0eSxCaWxsVG9TdGF0ZSxCaWxsVG9aaXBDb2RlLFNoaXBUb05hbWUs
U2hpcFRvQWRkcmV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JbmdyYW0gTWljcm8gLSAxMDAyNjI0MiIsDQ==

Thanks,its working & i am able to see the actual data but is there any way to see the actual data without resizing it to 64? Since that needs to be done manually,but i dont want to do it manually for every file.....

There are other tools, like base64 from GNU coreutils, and also quite a few online decoders, like http://www.base64decode.org/. If your files are not too big, the online decoders might be useful.

On my recent Linux:

base64 -d file
ClaimNumber,ClaimDealType,RejectionReason,DealNumber,SalesOrderNumber,HPSalesOrderNumber,InvoiceDate,InvoiceNumber,SKU,Quantity,SerialNumber,BillToName,EUserName,BillToAddress1,BillToAddress2,BillToCity,BillToState,BillToZipCode,ShipToName,ShipToAddress1,ShipToAddress2,ShipToCity,ShipToState,ShipToZipCode,EndUserName,EndUserAddress1,EndUserAddress2,EndUserCity,EndUserState,EndUserZipCode,BatchNumber,CompanyLocationID,DistributorName
"C124532","Volume HPN Switching Routing Applications Accessories NBO","","D721758","","","8/1/2013 12:00:00 AM","402561411","J9727A#ABA","2","","CAMERA CORNER CONNECTING POINT","BADGER SHEET METAL","GE COMMERCIAL DISTRIBUTION FIN CORP","DEALER #108250","WILLIAMSVILLE","NY","142210000","BADGER SHEET METAL","529 N MONROE AVE","","GREEN BAY","WI","543014909","BADGER SHEET METAL","529 N MONROE AVE","","GREEN BAY","WI","543014909","2422","10026242","Ingram Micro - 10026242",
"C124532","Volume HPN Switching Routing Applications Accessories NBO","","D721758","","","8/1/2013 12:00:00 AM","402561411","J9735A","2","","CAMERA CORNER CONNECTING POINT","BADGER SHEET METAL","GE COMMERCIAL DISTRIBUTION FIN CORP","DEALER #108250","WILLIAMSVILLE","NY","142210000","BADGER SHEET METAL","529 N MONROE AVE","","GREEN BAY","WI","543014909","BADGER SHEET METAL","529 N MONROE AVE","","GREEN BAY","WI","543014909","2422","10026242","Ingram Micro - 10026242",
"C124531","Volume PSG Notebooks NBO","","D647801","","","8/2/2013 12:00:00 AM","321737821","D8E66UT#ABA","11","","NETGAIN TECHNOLOGIES INC","CENTERS FOR YOUTH & FAMILIES","PO BOX 251970","","LITTLE ROCK","AR","722251970","CENTERS FOR YOUTH & FAMILIES","6501 W 12TH ST","","LITTLE ROCK",user@userPC:/mnt/9/$  & FAMILIES","6501 W 12TH ST","","LITTLE ROCK","AR","722041511","2422","10026242","Ingram Micro - 10026242",

It obviously consists of \r\n terminated liens.

Why do it manually, that sounds very tedious and unpleasant? Write a quick shell script to reformat it automatically.

Here is an awk-script that can do the job:

BEGIN {
    S = "";
}
{
    S = S $0;
    while (length(S) > 64)
    {
        print substr(S,1,64);
        S = substr(S,65);
    }
}
END {
    print S;
}

Usage:

awk -t script.awk <input >output

...provided that the file is not longer than the maximum line length. This limitation is true for this and all similar solutions (using sed , awk , fmt , etc.).

Wouldn't it be easier to use

fmt -64

instead?

I hope this helps.

bakunin

If you look closely, you'll find, that the working string S will never be longer than the longest line of the input file plus 63. The script adds one line to S and then writes 64 character portions to the output file until S is shorter than 64 characters.

The easiest way would be to use the base64 utility from the GNU coreutils, because it does not care about the proper 64-character-linelength, but it is not available everywhere.

You are right. There is a kernel constant called "MAX_LIN" in "/usr/sys/include/limits.h". If the file has lines longer than this "awk"s read will fail because this limitation is built into all line oriented utilities, including "awk" (and "sed", "fmt", "sort", "vi", ...).

I mentioned it because many people are not even aware of this intrinsic limitation, which might have different values across platforms, but is everywhere in place.

I hope this helps.

bakunin