Binary file encryption
Hi friends, i am tryin to encrypt binary file using secret key. When i decrypt the it seems taht it is damaged.
I write this code :
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
CipherOutputStream cos = new CipherOutputStream(new FileOutputStream(new
File(pathOut)), cipher);
FileInputStream fis = new FileInputStream(new File(pathIn));
byte[] buffer = new byte[bufferSize];
while ( (fis.read(buffer, 0, buffer.length)) >= 0) {
cos.write(buffer, 0, buffer.length);
cos.flush();
cos.close();
fis.close();I dont know what hapened. Can you help me please?
This is the decyption methode :
Cipher cipher = Cipher.getInstance(AES);
cipher.init(Cipher.DECRYPT_MODE, secretKey);
CipherInputStream cis = new CipherInputStream(new FileInputStream(new
File(pathIn)), cipher);
FileOutputStream fos = new FileOutputStream(new File(pathOut));
byte[] buffer = new byte[bufferSize];
while ( (cis.read(buffer, 0, buffer.length)) >= 0) {
fos.write(buffer, 0, buffer.length);
fos.flush();
fos.close();
cis.close();
Similar Messages
-
Hi Guys....I am facing decrypting a binary file which is encrypted
I am facing decrypting a binary file which is encrypted in C++ code. They use FULL RSA Service provider
wiht MD5 , TripleDES algorithms....i did the same in java to decrypt the file..but i am getting padding exception
javax.crypto.BadPaddingException: Given final block not properly padded
I am new to this group and topic...Anyhelp is greately appreciated..
C++ windows inbuilt methods for your idea to know what they use..
CryptAcquireContext (&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET)
CryptGenKey (hProv, CALG_3DES, CRYPT_EXPORTABLE, &hKey))
CryptGetUserKey (hProv, AT_KEYEXCHANGE, &hXchgKey))
CryptGenKey(hProv,AT_KEYEXCHANGE,NULL,&hXchgKey))
CryptExportKey (hKey, hXchgKey, SIMPLEBLOB, 0, pbKeyBlob, &dwKeyBlobLen))
CryptEncrypt(hKey, 0, endOfData, 0, pData, dataLength, *bufSize))
please tell me how to implemnet the same in java...
Thanks in advance,
shyam
Edited by: MuppidiJava on Dec 11, 2008 3:44 PMTry a cryptography forum
http://forums.sun.com/forum.jspa?forumID=9 -
Issue in reading a binary file, with 'Flatten to String' data.
I'm facing issue while reading a binary file (created using LabVIEW).
I've mentioned everything (issue and method to reproduce it) within the attached VI.
Same vi is attached in 2012 and 8.0 versions.
Regards
I am not allergic to Kudos, in fact I love Kudos.
Make your LabVIEW experience more CONVENIENT.
Solved!
Go to Solution.
Attachments:
Issue in VI.vi 26 KB
Issue in VI (Version 8.0).vi 43 KBmoderator1983 wrote:
crossrulz wrote:
The reading of a string from a binary file stops at a NULL character (0x00). When the first character is 0x00, you are just reading the one character. I would suggest writing to a byte array since you are doing the inverting. And then you can read as a byte array.
crossrulz:
U rocks..!!
you have hit bull's eye...!!
After playing around a little more, I think I might have misinformed you a little. If you explicitly tell it a string, it looks for the string length at the very beginning and reads that length of bytes as a string. It appears that if you implicitly tell it to read a string (not wire the data type) it reads all of the bytes directly, including the length of string you wrote.
Regardless, my advice is the same. You should just write and read using byte array. It is less conversions if you are performing your "encryption".
EDIT: Here's a snippet of the VI I was playing with to figure this out.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Attachments:
String Binary File.png 12 KB -
PI 7.1 Email Attachment binary file
Hi,
I am trying to attach a binary (encrypted) file to a regular mapped email (receiver adapter) before sending it.
It is similiar to attach pdf-files at the end of a mapping process.
Is there no way to attach binary files other than writing an adapter module?
Is there no generic "Attach File" module in PI 7.11?
I tried ASMA with XSLT, but the problem is, that the file is binary and the sender adapter would not read it without xml-format.
Any good idea?
thanks
hsHi Holger,
Just a suggestion:
1. Read the binary file using file adapter (in binary mode)
2. use a mail package and put the read content into the Content node of it. You can use this java mapping for it
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.DynamicConfiguration;
import com.sap.aii.mapping.api.DynamicConfigurationKey;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
import com.sap.aii.mapping.api.InputHeader;
public class JavaMapping extends AbstractTransformation {
public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException {
getTrace().addInfo("JAVA Mapping Called");
//Input payload is obtained by using arg0.getInputPayload().getInputStream()
String inData = convertStreamToString(arg0.getInputPayload().getInputStream());
String outData = inData
try
//8. The JAVA mapping output payload is returned using the TransformationOutput class
// arg1.getOutputPayload().getOutputStream()
arg1.getOutputPayload().getOutputStream().write(outData.getBytes("UTF-8"));
catch(Exception exception1) { }
public String convertStreamToString(InputStream in){
StringBuffer sb = new StringBuffer();
try
InputStreamReader isr = new InputStreamReader(in);
Reader reader =
new BufferedReader(isr);
int ch;
while((ch = in.read()) > -1) {
sb.append((char)ch);}
reader.close();
catch(Exception exception) { }
return sb.toString();
Then provide the filename dynamically into the ContentType of the mail package.
I guess this should work.
Regards
Suraj -
Can't decrypt binary file with PBE
Hi,
I'm writing an simple file transfer application using UDP that encrypts the data
before sending it with PBEWithMD5AndDES. Text files are encrypted and
decrypted fine, but binary files such as a JPG/EXE/DOC... are messed up
and an application can't open them on the other side. Has anyone experienced
such a problem?
ThanksBelow are my encrypt and decrypt functions.
Thanks in advance.
public byte[] encrypt(byte[] data)
PBEKeySpec pbeKeySpec;
PBEParameterSpec pbeParamSpec;
SecretKeyFactory keyFac;
ByteArrayOutputStream b=null;
DataOutputStream d =null;
// Salt
byte[] salt = {
(byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c,
(byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99
// Iteration count
int count = 1000;
// Create PBE parameter set
pbeParamSpec = new PBEParameterSpec(salt, count);
try{
pbeKeySpec = new PBEKeySpec(sessionPassword.toCharArray());
keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES","SunJCE");
SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
// Create PBE Cipher
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES","SunJCE");
// Initialize PBE Cipher with key and parameters
pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);
b = new ByteArrayOutputStream();
d = new DataOutputStream(b);
// create CipherOutputStream
CipherOutputStream out = new CipherOutputStream( b, pbeCipher );
// write contents to file and close
try {
for ( int i = 0; i < data.length; i++ )
out.write(data);
out.flush();
out.close();
// handle IOException
catch ( IOException exception ) {
exception.printStackTrace();
catch(Exception e){}
return(b.toByteArray());
public byte[] decrypt(byte[] data)
PBEKeySpec pbeKeySpec;
PBEParameterSpec pbeParamSpec;
SecretKeyFactory keyFac;
byte[] decryptedData=null;
// Salt
byte[] salt = {
(byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c,
(byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99
// Iteration count
int count = 1000;
// Create PBE parameter set
pbeParamSpec = new PBEParameterSpec(salt, count);
try{
pbeKeySpec = new PBEKeySpec(sessionPassword.toCharArray());
keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES","SunJCE");
SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
// Create PBE Cipher
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES","SunJCE");
// Initialize PBE Cipher with key and parameters
pbeCipher.init(Cipher.DECRYPT_MODE, pbeKey, pbeParamSpec);
Vector fileBytes = new Vector();
ByteArrayInputStream b = new ByteArrayInputStream(data);
CipherInputStream in = new CipherInputStream( b, pbeCipher );
byte contents = ( byte ) in.read();
while ( contents != -1 )
fileBytes.add( new Byte( contents ) );
contents = ( byte ) in.read();
in.close();
decryptedData = new byte[ fileBytes.size() ];
for ( int i = 0; i < fileBytes.size(); i++ )
decryptedData[ i ] = (( Byte )fileBytes.elementAt( i )).byteValue();
catch(Exception e){Gui.chatArea.append("exception:"+e+"\n");}
return(decryptedData); -
Hi All,
Can Oracle B2B accept binary file attachments in message payload?Hi Raj,
B2B can be used to transfer binary documents or binary attachments. For attachment, you need to use proper content type value. You may refer the supported values here -
http://www.b2bgurus.com/2007/11/attachment-feature-in-rosettanet-using.html
If it is required to receive docs as body of message, then for binary docs (pdf and jpeg), it may be done by enabling binary transfer at b2b -
http://www.b2bgurus.com/2008/10/pgp-encrypted-file-transfer.html
Let us know if you need any other info.
Regards,
Anuj -
Binary file 6049 of printserver WPS54G
I have problems with the WPA encryption, this should be better with the 6049 software. Now the 6050 sofware is installed and it's not possible to encrypt the WPA, only WEP. Linksys has no solution. Please help! I'm looking for the 6049 binary file..
There is no more available firmware on the Linksys download site.
I decided to use WEP for my printserver with my old router and added another newer router for my secured wireless network. -
Siebel 8.0.0.12 Fix Pack; Unable to get the seed from binary file.
Hello Folks,
Can anyone throw some light into what action is required on my scenario.
I have applied Fix Pack Siebel 8.0.0.12 on top of 8.0.0.11 SBA. After it is appled, I am facing a documented issue within the Release Notes for the 8.0.0.12 Fix Pack
The issue is "UNABLE TO LAUNCH URL AFTER APPLYING SIEBEL 8.0.0.12". I tried the steps given with the MR document, however, I am still having this issue.
I am also not sure what is expected at the step of; Run the following command: seedgeneratorutil myseed.dat abcdef .
It's asking me for a value to enter for seed at command prompt. "Enter the seed":
what I should give here. As an assumption values,I gave SADMIN and tried to launch but still shows up the same error
Please Assit
Steps Details from Release Notes:
UNABLE TO LAUNCH URL AFTER APPLYING SIEBEL 8.0.0.12
Component: Server Infrastructure
Subcomponent: SWSE
Product Version: Siebel 8.0.0.12
Base Bug ID: 11938270
**Users are unable to launch the URL after applying the Siebel 8.0.0.12 Fix Pack.
**Use the following workaround to address this issue:
Navigate to the eappweb/bin directory from the command line on the SWSE installation.
Run the following command:
seedgeneratorutil myseed.dat abcdef
NOTE: In the example, myseed.dat is a filename. You can give any file name you wish.
The myseed.dat file is generated in the eappweb/bin directory.
Edit eapps.cfg to include the following parameters under the SWE section:
seedfile = < complete path for myseed.dat >
Bounce the web server.
(For Linux only) Copy libmod_swe.so from the eappweb/bin folder to the web/ohs/modules folder
Thanks
KumarWilson,
Thanks for your reply.I have repeated the steps and regenerated the error messages.
Browser
Message:
An error occurred while trying to process your request. This error indicates a problem with the configuration of this server and should be reported to the webmaster (along with any errors listed below). We apologize for the inconvenience
Initialization error:
Unable to get the seed from binary file.
Log
2021 2011-09-20 23:23:01 0000-00-00 00:00:00 +0530 00000000 001 003f 0001 09 ss110920_7068 7068 7852 E:\sba80\SWEApp\log\ss110920_7068.log 8.0.0.12 [20444] ENU
ProcessPluginState ProcessPluginStateError 1 000000024e781b9c:0 2011-09-20 23:23:01 7852: [SWSE] Unable to get the seed from binary file.
Eapps.cfg
[swe]
Language = enu
Log = errors
LogDirectory = $(SWSERoot)\log
ClientRootDir = $(SWSERoot)
SessionMonitor = False
AllowStats = true
LogSegmentSize = 0
LogMaxSegments = 0
DisableNagle = False
seedfile = E:\sba80\SWEApp\BIN\80012seed.dat
Thanks
Kumar -
Hi All , can anyone help me here ...
I used “Write to Binary” to write my report , at first stage this file is writing headers , including column headings . at 2nd writing stage it is writing data in columns. This file can be viewed in .doc or .xls format. I have three issues
1. If I want to print this file from Front Panel , what I should do?
2. other thing is if I stop logging and then start for another span , it starts writing from the first line instead of from last line , because of this problem it is causing over-writing .
3 another thing , lets say if for 2nd or 3rd logging , I want to display sub-headings (test-1 , test-2) , how to insert , for example :
MAIN HEADING (COMPANY NAME , REPORT TITLE )
DATE , PRODUCT INFO , OPERATOR NAME
COL1 COL2 COL3 COL4
Subheading (test-1)
Value1 Value2 Value3 Valye4
Value1 Value2 Value3 Valye4
Value1 Value2 Value3 Valye4
Subheading (Test-2)
Value1 Value2 Value3 Valye4
Value1 Value2 Value3 Valye4
Value1 Value2 Value3 Valye4
Any help in this regard will be highly appreciated.
Regards
Faiyaz
Attachments:
report-writing-binaryfile.vi 68 KB
02-display-subVI.vi 12 KBHi Faiyaz,
1. How Do I Print a File Programmatically From LabVIEW?
2. Please the Programming >> File I/O >> Advanced File Functions >> Set File Position function on the block diagram after the Open/Create/Replace File function and set the from input to "end." This will append new data to the end of the file.
3. You can simply add that information to the Format into String you are writing to the second Write to Binary file.
Michael K.
| Michael K | Project Manager | LabVIEW R&D | National Instruments | -
How to open and read binary files?
How do I open and read Binary files?
Did you look on The Unarchiver's web site where it has a link to older versions? http://theunarchiver.googlecode.com/files/TheUnarchiver3.2_legacy.zip
The best thing to do is ask your friends what programs they used to produce these files, or at least what format files they are producing. Otherwise it's like being shown a car and given a bundle of 200 keys with no idea to which one to use, or even if any of them work with that car.
Using The Unarchiver will likely not do anything because it too will not know what format files are involved, and they may not even been in an archived format. If they sent you a Word file without telling you (a favorite of Windows users to do -- it drives me crazy when they could have just sent them in plain text), The Unarchiver won't open them. If it's a picture file then using Hexedit will just show you a bunch of unintelligible stuff as shown in an earlier post, though you may see a line of text providing a hint.
As I said earlier, often .bin may be an executable program which needs another program to actually interpret it. That's what Java is trying to do. Still, it may think it can execute the file, but it is highly unlikely somebody would send you an executable program (and if they did I would not trust it). For all you know it may be a Windows virus. -
everytime i download a show or movie from the internet a pop up asks me:
"you have chosen to open xxxxxx which is a: Binary File from: httpxxxxx would you like to save this file - SAVE or CANCEL"
this never used to happen on the older versions of firefox. it is so annoying - is there any way to turn it off?
i am running mac os 10.5.8 and no, there is no option to click a 'don't ask me again' feature in the pop-up dialog.I'd first try downloading an installer from the Apple website using a different web browser:
http://www.apple.com/quicktime/download/
If you use Firefox instead of IE for the download (or vice versa), do you get a working installer? -
Reading an object from a binary file
i am writing objects into my binary file using printwriter class. i am able to write objects into the file but i am having problems reading the object from the file. is there any other way of going about it. i tried using the objectoutputstream and object input stream class. but i am getting run time errors coz of something to do with serialization
i am storing records as a object into a binary file so that it is easy to seek my recordsOf course you have trouble reading objects after you wrote them with a PrintWriter.
You should rather have fixed the Serialization errors: only objkects that implement Serializable correctly can be serialized. -
DE PDP-1 binary file from Java
Can someone here help me, please!?
Anyone know how to convert a Java class file into a binary file that will run natively on my Digital PDP-1 computer? I just spent over $120,000 for it! Thanks.
This resurrected thread was first posted November 25, 1960 at 8:25AM
-------------------------------------------------------------------------This resurrected thread was first posted November 25,
1960 at 8:25AMIn what time zone? -
How can I open different binary files from BLOB column ?
If we store some type of binary file (XLS, DOC, PDF, EML and so on, not only pictures) in BLOB column how can I show the different contents? We use designer and forms 9i with PL/SQL.
How can I copy the files from BLOB to file in a directory or how can I pass BLOB's content to the proper application directly to open it?The mime type is just a string as explained above (e.g. application/pdf...). There are lot of samples here and on metalink.
E.g. add a column mime_type varchar(30) to your blob table. Create a procedure similar to the following:
PROCEDURE getblob
(P_FILE IN VARCHAR2
IS
vblob blob;
vmime_type myblobs.mime_type%type;
length number;
begin
select document, mime_type into vblob,vmime_type from myblobs where docname = p_file;
length := dbms_lob.getlength(vblob);
if length = 0 or vblob is null then
htp.p('Document not available yet.');
else
owa_util.mime_header(vmime_type);
htp.p('Content-Length: ' || dbms_lob.getlength(vblob));
owa_util.http_header_close;
wpg_docload.download_file(vblob);
end if;
exception
when others then
htp.p(sqlerrm);
END;
Create a DAD on your application server (refer to documentation on how to create a DAD).
Display the blob from forms (e.g. on a when-button-pressed trigger):
web.show_document('http://myserver:port/DAD/getblob?p_file=myfilename','_blank');
For storing blobs in a directory on your db server take a look at the dbms_lob package.
For storing blobs in a directory on your app server take a look at WebUtil available on OTN.
HTH
Gerald Krieger -
How do you open multiple binary files and plot them all on the same graph?
I have three different binary files and I want to plot all 3 of them onto a graph.
I am familiar with opening and reading a single binary file. (Thanks to the help examples!)
But to do multiple numbers at the same time? I was thinking of putting 3 different 'reading from binary file' blocks with the rest of the 'prompts', 'data type', etc.. and then connecting them on the same wire.
However, I got into a mess already when I tried to read one .bin file to dynamic data type --> spectral measurements --> graph waveform. The error was Not enough memory to complete this operation... Why is that? That didnt happen in the help example "Read Binary File.vi"... Has it got something to do with the dynamic data type?
Thank you for your time.
Jud~Have a look at the image below and attached VI. Simply enter the different paths into the PathArray control.
R
Message Edited by JoeLabView on 07-30-2008 09:59 PM
Attachments:
multipleBinary2Graph.vi 18 KB
multipleBinary.PNG 5 KB
Maybe you are looking for
-
How do I access it on my computer? Do all my files automatically go there?
I don't know how to access my files on Icloud, especially to see if I have the Find My IPhone program. Do any files go? Or just Itunes things?
-
I can no longer minimize my dreamweaver window.
Hi there, I'm not 100% sure if this question has already been answered on this site because I didn't get a chance to skim through all the posts. Anyway, up until a couple days ago I can no longer minimize my dreamweaver window. Now, I am not talking
-
When calling my skype number, the number is always busy......why? Nobody can contact me....
-
HT4859 is mobile me the same as Icloud for my mac pro?
im trying to get my devices synced but I cannot find Icloud on my macbook
-
How do I import key commands from Logic 9 to Logic X?
I have downloaded key commands from a friend. They're very good and convenient and I would like to not set them all manually. That'll take a long time. So he just told me to download his key commands, and he showed me how to import them. However we c