How to export key in smart card to byte array?
How to export key in smart card to byte array?
I want to export key to byte array to xor with some data. How can I do?
I use java card kit 1.2.1 and jdk1.3.1_02
Thanks
Can I write like this?
import javacard.security.*;
/* in method */
byte[] keyExoprt = new byte[64];
Key v = Key.buildKey(KeyBuilder.TYPE_DSA_PRIVATE,KeyBuilder. LENGTH_DSA_512, false);
short a = DSAPrivateKey.getX(keyExport, KeyBuilder. LENGTH_DSA_512);
////////////////////////////////////////////////////////////////////////////////////////
Similar Messages
-
Generate public private keys inside smart card
Dear all,
I am using this code to generate public and private key inside the smart card.
KeyPair kp = new KeyPair(KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_RSA_512);
kp.genKeyPair();
PrivateKey prikey = kp.getPrivate();
PublicKey pubkey = kp.getPublic();
This code is executing without errors.
I need to get out the public key from the smart card. So I need to get public key to a byte array.
But I can't get those keys to plain text byte array.
The methods that I can get for pubkey object are
pubkey.clearKey();
pubkey.equals(obj);
pubkey.getSize();
pubkey.getType();
pubkey.isInitialized(); only these.
I am using
Eclipse Version: 3.4.1 (Compiler complience level = 1.4)
Jcop plugin (to communicate with the actual card and to test the java code in virtual card provided by JCOP)
OmniKey5321 card reader (In contactless type)
What is the reason to get only those above methods to pubkey object? Is it a version problem?
How can I get the public key to plain byte array? Is it possible?
If it is not possible Is there a way to get public key as a export certificate or something other solution?
If my scenario is not a possible strategy, How can I use public private keys to send specific data to applet? Is there a better way to do this?
Edited by: 863766 on Jun 6, 2011 12:16 AMThank you very much!
I used this code
RandomData rand = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
short lenBytes = (short) (KeyBuilder.LENGTH_DES/8);
byte[] buffer = JCSystem.makeTransientByteArray(lenBytes,JCSystem.CLEAR_ON_DESELECT);
DESKey key = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES , KeyBuilder.LENGTH_DES,false);
rand.generateData(buffer, (short) 0 ,lenBytes);
key.setKey(buffer, (short) 0 ) ;
byte keyData[]= new byte[256];
key.getKey(keyData, (short) 0);
Now I know how to initialize the key...
Thank you again.
Regards,
Dushantha
Edited by: 863766 on Jun 6, 2011 3:52 AM -
How to export sequence to P2 card?
Hi everybody
I saw a tutorial in Adobe webpage explaining how to export sequence back to P2 Card, as Premiere CS3.2 (updated) is able to recreate, from a edited timeline, all the folder and file system needed to be read on a P2 card under mxf format.
This can be a great way to export full resolution HD edited footage from one PC to another.
Unfortunately, I cannot find "export to P2" choice in my menu. I get export to Encore, to Tape, but no "P2" mention. But this mention appear in the Adobe tutorial... concernig any version from Premiere CS3.1
How comes this feature doesn't appear anywhere into the menu of my Premiere pro CS3, version 3.2?
Any clue?
ThanksI found the link explaining how to do it.
http://livedocs.adobe.com/en_US/PremierePro/3.0/help.html?content=WSE32B8568-2904-4e95-861 A-F09F75AA6C7B.html
Here is what they say:
"Select the sequence or clip in the Timeline panel or Project panel.
(Optional) If exporting from the Timeline, set a timeline marker, numbered 0 on the frame you want used as the P2 icon for the exported.
If you do not set this marker, the first frame of the sequence will appear as the P2 icon by default.
Choose File > Export > Export To P2."
Problem is that: I don't get any "export to P2" at this place in my Premiere CS3.2 -
How can use a CAC smart card on an iPad 3?
How can I use a CAC givernment smart card on an iPad 3. I am using citrix receiver to access the system.
Some suggestions were made in this thread from last year:
https://discussions.apple.com/thread/2770317?start=0&tstart=0
I don't know whether any are still viable, but it might be a place to start.
Regards. -
How to load applet to smart card.
I'm new in smart card world and at this moment try to run examples.
I have java_card_kit-2_2_2-windows and GPShell-1.4.2
I have successfuly run all examples from card kit with use of cref (emulator) and now I whant to run simple example with real card.
I have a card reader: CardMan 3x21 (USB)
In diagnostic tool it shows me card ATR: 3B 69 00 FF 4A 43 4F 50 32 31 56 32 32
Protocol T=0
But I can find this ATR in smartcard_list.txt (http://ludovic.rousseau.free.fr/softwares/pcsc-tools/smartcard_list.txt)
The most closest match
3B 66 00 FF 4A 43 4F 50 33 30
JCOP30 "OP-DI 16k VISA v2 (JCOP30) ORGA"
I suspect that I have JCOP21 ORGA card (from my customer info)
1) When I try to run GPShell HelloInstall.txt the scrip executed until insatll aplet
it writes error messge: "reference data not found..."
2) With apdutool from card kit I cant even connect to card reade...
Could any body sugest me what I should try next?Hello all!
I gain some progress by my self, but still has questions.
1) Form card manufacturer I get that I have following card:
JCOP 21 v2.2:
ISO7816
JavaCard 2.2.1, GlobalPlatform: 2.1.1
EEPROM: 36kb
RAM: 3kb
2) I can run some scripts with GPShell 1.4.2
Here dump for geting CPLC info
mode_211
enable_trace
establish_context
card_connect
* reader name OMNIKEY CardMan 3x21 0
send_apdu -sc 0 -APDU 80CA9F7F00
* Command --> 80CA9F7F00
* Wrapped command --> 80CA9F7F00
Response <-- 9F7F2A479051144051515824006334008574910828481063414F5A70810C2A5E303835373400000000000000009000
card_disconnect
release_context
BUT when I try to install HelloWorld.cap (compiled with Sun Java Dev Card Kit) I get an error, Here the dump for helloInstallGP211.txt:
mode_211
enable_trace
establish_context
card_connect
* reader name OMNIKEY CardMan 3x21 0
select -AID a000000003000000
Command --> 00A4040008A000000003000000
Wrapped command --> 00A4040008A000000003000000
Response <-- 6F108408A000000003000000A5049F6501FF9000
open_sc -security 1 -keyind 0 -keyver 0 -mac_key 404142434445464748494a4b4c4d4e4f -enc_key 404142434445464748494a4b4c4d4e4f // Open secure channel
Command --> 80CA006600
Wrapped command --> 80CA006600
Response <-- 664C734A06072A864886FC6B01600C060A2A864886FC6B02020101630906072A864886FC6B03640B06092A864886FC6B040215650B06092B8510864864020103660C060A2B060104012A026E01029000
Command --> 8050000008CD0C9119FE40284200
Wrapped command --> 8050000008CD0C9119FE40284200
Response <-- 00006334008574910828FF0200195EE3440DED201097D97CE9A1EFBB9000
Command --> 84820100103151BFEE8E943D724C52BB5CBAEB9B58
Wrapped command --> 84820100103151BFEE8E943D724C52BB5CBAEB9B58
Response <-- 9000
delete -AID a00000006203010c0101
Command --> 80E400800C4F0AA00000006203010C010100
Wrapped command --> 84E40080144F0AA00000006203010C010109F87161B011ED0B00
Response <-- 6A88
delete_applet() returns 0x80206A88 (6A88: Referenced data not found.)
delete -AID a00000006203010c01
Command --> 80E400800B4F09A00000006203010C0100
Wrapped command --> 84E40080134F09A00000006203010C01A50B15072D4EC04E00
Response <-- 6A88
delete_applet() returns 0x80206A88 (6A88: Referenced data not found.)
install -file HelloWorld.cap -nvDataLimit 2000 -instParam 00 -priv 2
file name HelloWorld.cap
Command --> 80E602002009A00000006203010C0108A000000003000000000AEF08C60201B0C80207D00000
Wrapped command --> 84E602002809A00000006203010C0108A000000003000000000AEF08C60201B0C80207D000F8A03543D4C4DFF400
Response <-- 009000
Command --> 80E80000EFC48201A5010013DECAFFED010204000109A00000006203010C0102001F0013001F000E00150036000C0067000A00130000006C00000000000002010004001502030107A0000000620101000107A000000062000103000E010AA00000006203010C0101001406000C00800301000107010000001F070067000210188C000118110100900B8700188B00027A02308F00033D8C00043B7A0523198B00052D198B0006320329041F651B1A08AD0016041F8D00073B16041F41290419088B00083270E6198B00093B19160408418B000A1903088B000B19AD000316048B000C7A08000A0000000000000000000005003600
Wrapped command --> 84E80000F7C48201A5010013DECAFFED010204000109A00000006203010C0102001F0013001F000E00150036000C0067000A00130000006C00000000000002010004001502030107A0000000620101000107A000000062000103000E010AA00000006203010C0101001406000C00800301000107010000001F070067000210188C000118110100900B8700188B00027A02308F00033D8C00043B7A0523198B00052D198B0006320329041F651B1A08AD0016041F8D00073B16041F41290419088B00083270E6198B00093B19160408418B000A1903088B000B19AD000316048B000C7A08000A0000000000000000000005003600E276C3872CCE4ACF
Response <-- 6A80
load_applet() returns 0x80206A80 (6A80: Wrong data / Incorrect values in command data.)
Does any body nows why this script failed? OR I should write bug report for GPShell ?
Alexey. -
How to find the last element of a byte array
Dear all,
I have a byte array with a max lenght of 1024*50 bytes. In that array I store the bytes read from a file. How can I find where the array ends (i.e. which is the last valid element of the byte array)?
Thank you for your help.
Best Regards,
JIMI want to send files over TCP connection using BufferedOutputStreams and BufferedInputStreams. The first side (e.g. the client) sends a file (e.g mp3 file or jpeg image) to the server using the code
public void sendFile(Socket s, String FileName) throws Exception
BufferedOutputStream out = new BufferedOutputStream(s.getOutputStream());
BufferedInputStream in = new BufferedInputStream(new FileInputStream(FileName));
int len = 0;
while ( (len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
in.close();
out.flush();
}(The client does not close the BufferedOutputStream out because other files will be sent afterwards)
Then, the server receives the file using the code:
public void receiveFile(Socket s, String FileName) throws Exception
OutputStream out = new BufferedOutputStream(new FileOutputStream(FileName));
InputStream in = new BufferedInputStream(s.getInputStream());
int len = 0;
while ( (len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
break;
out.flush();
out.close();
}(likewise the InputStream in is not closed for the same reasons).
In order the server to receive the file and stop reading the BufferedInputStream, I will have to make some modifications to this part of the code,
while ( (len = in.read(buffer)) > 0)so as to know when the whole file has been received.
Thus, even if I send the length of each file, I will not be able to read it. Could you please recommend me a solution? -
How to convert an int number to a byte array, and how to convert back?
Hello, everybody,
Just as the topic, if I have an int number(which should have 32-bit, or 4-byte), how can I convert it into a byte array. And also, how to convert it back.
Thank you in advance!Alternatively you can use ByteBuffers to do this work for you
// to a Byte Array
int originalInt =...;
ByteBuffer myBuffer = ByteBuffer.allocate(4);
myBuffer.putInt( originalInt );
byte myArray[] = myBuffer.array();
// and back to an int
ByteBuffer myOtherBuffer = ByteBuffer.wrap(myArray);
int finalInt = myOtherBuffer.getInt(); -
How to Compile and run Smart Card Application
hi
any one can help me reagrding Javacard API. i download the JavaCard Development Kit from sun and install on my machine but i didn't get all java files and class files of JavaCard API. where i obtain those files so my application get compile and run.
pls help me i m new in this technology.
Thanks in Advance.My program Test.java in F:\Tomcat5\webapps\Ambika\WEB-INF\Classes. I compiled in the format below. I got like this. What should I do for this? But yesterday I compiled like this only, It compiled and the folder com\cert\Test.class is created. Today again I compiled the pgm after deleting the already created folder 'com\cert', I got the error like this.
I've given my pgm and the thing I've got when I compiled it.
Test.java
package com.cert;
public class Test
public void display()
System.out.println("Hai");
F:\Tomcat5\webapps\Ambika\WEB-INF\Classes>javac -d F:\Tomcat5\webapps\Ambika\WEB-INF\Classes\Test.java
javac: no source files
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are u
sed
-classpath <path> Specify where to find user class files
-cp <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-d <directory> Specify where to place generated class files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-version Version information
-help Print a synopsis of standard options
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system
F:\Tomcat5\webapps\Ambika\WEB-INF\Classes>
Plz help me.
thanks in advance
Ambika -
How to stop and resume smart card reader handle using OCF framework
I need to stop the reader handle and transfer the handle to other application and after reply from that application, i have to resume the reader handle.
I tried Smartcard.shutdown and then I used SmartCard.start but it doesnt help.
Can anyone help me to sort out this issue?
Provide some sample code if possible.
Thanking you in advance.with ocf you have CardTerminal instances to represent readers.
Did you try the close() method on your CardTerminal instance?
afterwards, you can open() it. -
How to make a deck of cards in 2D array
Yes you have told me to use enums but my teacher JUST told me I'd fail if i did enums. she wnats me to do it in a 2d array
Ryan Reese
This is like a poker simulation. Won't make it a GUI yet =/
Started December 8th, 2008
//Importing a crap load of stuff to make this work
import java.util.Scanner;
import java.util.Random;
//Start the public class
public class Poker
//deck[suit][rank]
public static String[][] deck={{"CLUBS","DIAMONDS","SPADES","HEARTS"},{"TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE","TEN","JACK","QUEEN","KING","ACE"}};
//start the main method
public static void main(String args[])
//Initialize a variable representing poker. I can call methods and such now.
Poker poker=new Poker();
//Make it so i can read user input
Scanner input=new Scanner(System.in);
//Random generator
Random generator=new Random();
//Welcome the user and such.
System.out.println("Welcome to Poker!");
//Make the 5 cards
String card1=deal(generator.nextInt(4),generator.nextInt(12));
String card2=deal(generator.nextInt(4),generator.nextInt(12));
String card3=deal(generator.nextInt(4),generator.nextInt(12));
String card4=deal(generator.nextInt(4),generator.nextInt(12));
String card5=deal(generator.nextInt(4),generator.nextInt(12));
//Redeal 5 cards. May not be needed
String card6=deal(generator.nextInt(4),generator.nextInt(12));
String card7=deal(generator.nextInt(4),generator.nextInt(12));
String card8=deal(generator.nextInt(4),generator.nextInt(12));
String card9=deal(generator.nextInt(4),generator.nextInt(12));
String card10=deal(generator.nextInt(4),generator.nextInt(12));
System.out.println("Here are your 5 starting hands\n");
//Print out original 5 cards
System.out.println("1)"+card1);
System.out.println("2)"+card2);
System.out.println("3)"+card3);
System.out.println("4)"+card4);
System.out.println("5)"+card5);
//See which cards the user hates.
System.out.println("Would you like to keep card one/two/three/four/five?");
//Keep track of which they want to keep
boolean keepCard1=input.nextBoolean();
boolean keepCard2=input.nextBoolean();
boolean keepCard3=input.nextBoolean();
boolean keepCard4=input.nextBoolean();
boolean keepCard5=input.nextBoolean();
//If they dont want to keep card 1..then redeal
//So on and so forth
if(!keepCard1)
card1=card6;
if(!keepCard2)
card2=card7;
if(!keepCard3)
card3=card8;
if(!keepCard4)
card4=card9;
if(!keepCard5)
card5=card10;
//Print out the original 5 cards.
System.out.println("1)"+card1);
System.out.println("2)"+card2);
System.out.println("3)"+card3);
System.out.println("4)"+card4);
System.out.println("5)"+card5);
//Give user the new cards
System.out.println("Here are your (new) 5 cards");
System.out.println("1)"+card1);
System.out.println("2)"+card2);
System.out.println("3)"+card3);
System.out.println("4)"+card4);
System.out.println("5)"+card5);
//Determine what kind of hand the user has.
String hand=poker.determineHand(card1,card2,card3,card4,card5);
System.out.println(hand);
//Exit the program
System.exit(0);
public static String deal(int suit,int rank)
String card="";
//Making the deck out of the 2D array
for(int i=0;i<suit;i++)
for(int n=0;n<rank;n++)
return card;
public static String determineHand(String card1,String card2,String card3,String card4,String card5)
//Some awesome crap here to determine what kind of hand the user has
String hand="You have a ";
//If it is a flush
return hand;
}Inside those two for loops, what exactly should i do? I'm thinking have an array cards[][] and in each position like cards[0][0]//that is 2 of clubs
that sound right or something? Then impliment something to shuffle?This is probably how you would've done it 10 years ago...
Ryan Reese
This is like a poker simulation. Won't make it a GUI yet =/
Started December 8th, 2008
//Importing a crap load of stuff to make this work
import java.util.Scanner;
import java.util.Random;
//Start the public class
public class Poker
//deck[suit][rank]
public static String suits[]={"CLUBS","DIAMONDS","SPADES","HEARTS"}, ranks[]={"TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE","TEN","JACK","QUEEN","KING","ACE"};
//start the main method
public static void main(String args[])
//Initialize a variable representing poker. I can call methods and such now.
Poker poker=new Poker();
//Make it so i can read user input
Scanner input=new Scanner(System.in);
//Random generator
Random generator=new Random();
//Welcome the user and such.
System.out.println("Welcome to Poker!");
String cards[]=new String[5],morecards[]=new String[5];
// Initialize the deck
int deck[][]=new int[13][4];
for(int i=0;i<13;i++)for(int j=0;j<4;j++)deck[i][j]=-1;
//Make the 5 cards
for(int i=0;i<5;i++){
int suit=generator.nextInt(4),rank=generator.nextInt(13);
while(deck[rank][suit]!=-1){
suit=generator.nextInt(4);rank=generator.nextInt(13);
cards=rank*4+suit;
deck[rank][suit]=-1;
//Redeal 5 cards. May not be needed
for(int i=0;i<5;i++){
int suit=generator.nextInt(4),rank=generator.nextInt(13);
while(deck[rank][suit]!=-1){
suit=generator.nextInt(4);rank=generator.nextInt(13);
morecards[i]=rank*4+suit;
deck[rank][suit]=-1;
System.out.println("Here are your 5 starting hands\n");
//Print out original 5 cards
for(int i=0;i<5;i++)System.out.println((i+1)+")"+ranks[cards[i]/4]+" "+suits[cards[i]%4]);
//See which cards the user hates.
System.out.println("Would you like to keep card one/two/three/four/five?");
//Keep track of which they want to keep
boolean keepCard[]=new boolean[5];
for(int i=0;i<5;i++)keepCard[i]=input.nextBoolean();
//If they dont want to keep card 1..then redeal
//So on and so forth
for(int i=0;i<5;i++)if(keepCard[i]==false)cards[i]=morecards[i+5];
//Print out the original 5 cards.
for(int i=0;i<5;i++)System.out.println((i+1)+")"+ranks[cards[i]/4]+" "+suits[cards[i]%4]);
//Give user the new cards
System.out.println("Here are your (new) 5 cards");
for(int i=0;i<5;i++)System.out.println((i+1)+")"+ranks[cards[i]/4]+" "+suits[cards[i]%4]);
//Determine what kind of hand the user has.
String hand=poker.determineHand(card1,card2,card3,card4,card5);
System.out.println(hand);
//Exit the program
System.exit(0);
public static String determineHand(String card1,String card2,String card3,String card4,String card5)
//Some awesome crap here to determine what kind of hand the user has
String hand="You have a ";
//If it is a flush
return hand;
...Happy holidays... -
How do I read directly from file into byte array
I am reading an image from a file into a BuffertedImage then writing it out again into an array of bytes which I store and use later on in the program. Currently Im doing this in two stages is there a way to do it it one go to speed things up.
try
//Read File Contents into a Buffered Image
/** BUG 4705399: There was a problem with some jpegs taking ages to load turns out to be
* (at least partially) a problem with non-standard colour models, which is why we set the
* destination colour model. The side effect should be standard colour model in subsequent reading.
BufferedImage bi = null;
ImageReader ir = null;
ImageInputStream stream = ImageIO.createImageInputStream(new File(path));
final Iterator i = ImageIO.getImageReaders(stream);
if (i.hasNext())
ir = (ImageReader) i.next();
ir.setInput(stream);
ImageReadParam param = ir.getDefaultReadParam();
ImageTypeSpecifier typeToUse = null;
for (Iterator i2 = ir.getImageTypes(0); i2.hasNext();)
ImageTypeSpecifier type = (ImageTypeSpecifier) i2.next();
if (type.getColorModel().getColorSpace().isCS_sRGB())
typeToUse = type;
if (typeToUse != null)
param.setDestinationType(typeToUse);
bi = ir.read(0, param);
//ir.dispose(); seem to reference this in write
//stream.close();
//Write Buffered Image to Byte ArrayOutput Stream
if (bi != null)
//Convert to byte array
final ByteArrayOutputStream output = new ByteArrayOutputStream();
//Try and find corresponding writer for reader but if not possible
//we use JPG (which is always installed) instead.
final ImageWriter iw = ImageIO.getImageWriter(ir);
if (iw != null)
if (ImageIO.write(bi, ir.getFormatName(), new DataOutputStream(output)) == false)
MainWindow.logger.warning("Unable to Write Image");
else
if (ImageIO.write(bi, "JPG", new DataOutputStream(output)) == false)
MainWindow.logger.warning("Warning Unable to Write Image as JPEG");
//Add to image list
final byte[] imageData = output.toByteArray();
Images.addImage(imageData);
If you don't need to manipulate the image in any way I would suggest you just read the image file directly into a byte array (without ImageReader) and then create the BufferedImage from that byte array.
-
How to pass a Word Document into a byte array?
Hi All
I have an application wherin i select multiple files and send them over to a webservice method.The files selected are zipped internally and sent across as a single entity.
I could pass the files and retrieve them using my test tool to check thir successful send and retrieval as long as the files were in "text" format.
But now i need to figure a way out to pass word docs or any other content types.I tried passing word docs in the mechanism that works fine for "text" files.But when i retrieve the files,and try to open the word documents the MS Word states that "the file is corrupt and cannot be opened". The following is the code.
public byte[] getContent(IDfSessionManager sessionManager,String repositoryName, String objectIdString) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
StringBuffer sb = new StringBuffer("");
try {
System.out.println("Repository Name " + repositoryName);
mySession = sessionManager.getSession(repositoryName);
// Get the object ID based on the object ID string.
DfId dfId = new DfId(objectIdString);
if (dfId.isObjectId())
System.out.println("Successfully fetched id " + dfId);
IDfSysObject sysObj = (IDfSysObject) mySession.getObject(dfId);
System.out.println("Content Type ++++++ " + sysObj.getContentType());
ByteArrayInputStream buf = sysObj.getContent();
int i = 0;
InputStreamReader readInput = new InputStreamReader(buf, "UTF8");
BufferedReader br = new BufferedReader(readInput);
while (br.ready()) {
sb.append(br.readLine());
sb.append("\n");
String captureText = sb.toString();
try {
is = new ByteArrayInputStream(captureText.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
final int BUF_SIZE = 1 << 8; // 1KiB buffer
byte[] buffer = new byte[BUF_SIZE];
int bytesRead = -1;
while ((bytesRead = is.read(buffer)) > -1) {
outputStream.write(buffer, 0, bytesRead);
is.close();
System.out.println("This is byte acquisition ###### >>>>>>>>>>>>>>>>>>>");
binaryData = outputStream.toByteArray();
File temp1 = File.createTempFile("Test",".docx");
FileOutputStream fos = new FileOutputStream(temp1);
fos.write(binaryData);
fos.close();
// Handle any exceptions.
catch (Exception ex) {
ex.printStackTrace();
finally {
sessionManager.release(mySession);
return binaryData;
}I assume that UTF8 must be applicatbe only to deal with .txt files.
I would really appreciate your guidance to obtain a way to acquire data from word documents so that i could open and read them without errors.
Thank You
RegardsHi B1J001
Following your suggestion i curtailed the code as follows:
public byte[] getContent(IDfSessionManager sessionManager,String repositoryName, String objectIdString) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
StringBuffer sb = new StringBuffer("");
try {
System.out.println("Repository Name " + repositoryName);
mySession = sessionManager.getSession(repositoryName);
// Get the object ID based on the object ID string.
DfId dfId = new DfId(objectIdString);
if (dfId.isObjectId())
System.out.println("Successfully fetched id " + dfId);
IDfSysObject sysObj = (IDfSysObject) mySession.getObject(dfId);
System.out.println("Content Type ++++++ " + sysObj.getContentType());
ByteArrayInputStream buf = sysObj.getContent();
*String testbuf = buf.toString();*
*testbytearray = testbuf.getBytes();*
File temp1 = File.createTempFile("Test",".docx");
FileOutputStream fos = new FileOutputStream(temp1);
fos.write(testbytearray);
fos.close();
// Handle any exceptions.
catch (Exception ex) {
ex.printStackTrace();
finally {
sessionManager.release(mySession);
return testbytearray;
}I am using just the ByteArrayInputStream to access the content. Still my attempt to open the document from the temporary file yields "file corrupt message".Am i going the right path?
Thank You
Regards -
PKI Certificates on smart cards.
Hi techies,
I am a Smart card operating system developer.
I m working on a PKI OS project.
and i m stuck while implementing the verify certificate command.
Well currently the issue i m facing is how to store certificates on smart card.
i mean which file to use, which format to use, (may be x.509), which document is relevent for implementation point of view.
could anybody help me out.
Regards,
Rishabh AgarwalHi Polat,
thanks for reply as i thought i wont have any reply.
well I am talking about a native card not a java card but i think it doesnt make any diffrence as at application level both are same. (diffrent at implementation level not application level)
so here i got some clue after searching meterial and brainstorming... we need to read following documents
1) PKCS#1 v2.1
2) PKCS#15
3) PKCS#7 (may be, as i havent gone through it yet)
I am almost ready with my OS for native card and have tested some its features except related to certificate...
Now i want to test it with some CSP application i dont know how will it go... i m trying to get some demo CSP code in which i can change and test my card by integrating it to some windows aplications.
if you have any clue about abovementioned then pls let me know..
and please ask if you need any help from my side
Regards
Rishabh Agarwal -
How do I store an Int, a short, and multiple bytes from file in byte array
I'm attempting to do this for a project but can't figure out how to store the three values in one byte array. This is what i've tried
public void send(byte[] input)
// TODO
ByteArrayInputStream bais = new ByteArrayInputStream(input);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
byte[] pData = new byte[100];
try {
dos.writeShort(checkSum);
dos.writeInt(nextSeqNum);
pData=baos.toByteArray();
bais.read(pData);
} catch (IOException e) {
DatagramPacket dgp = new DatagramPacket(pData, pData.length);When i set pData=baos.toByteArray() it changes the size and then stops me from being able to read the other 94 bytes into the array to send. Any ideas?You don't need the ByteArrayInputStream at all.
dos.writeShort(checkSum);
dos.writeInt(nextSeqNum);
dos.write(input);
pData = baos.toByteArray();
When i set pData=baos.toByteArray() it changes the sizeNo, it makes it refer to a new byte[] array containing what you've written to the BAOS. That's what it's supposed to do. -
How to put a String into a byte array
How can i put a String into a byte array byte[]. So that i can send it to the serial port for output to an LCD display. Cheers David
javadocs for String
getBytes
public byte[] getBytes()
Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.
Returns:
The resultant byte arraySince:
JDK1.1
Maybe you are looking for
-
Is it normal for the fan to run at all time ?????
The fan of my imac g5 1.6, never stops runing, its to the point that its anoying. And lately, the fan gets super loud, and frezes the computer, and i have to force quit to get thing back to normal...what can i do ?????
-
I have this below sample query with multiple joins involved, which is taking longer time than usual like around more than 5-10 min in the reports. I have 100,000 records in the application table. I started noticing the query got slowed down when i jo
-
Clients not receiving addresses from DHCP
I have a Cisco 2811 router and have configured it to be a DHCP server at a remote site. It seems like it should be pretty straight forward to configure DHCP. Apparently I'm missing something because I can't get clients to receive an address. Below
-
Use event handler programmatically
Hello, I use the Labview 8.2.1 and I would like to ask something about event handler. I have some buttons and I use an event handler to perform their tasks. The buttons are used only with the mouse and not programmatically. Now, I want to use a butto
-
Dynamic Min Max values of Axis
Hi Everybody, Just wanna know if there is any possibility to assign dynamically min-max values of Y axis in line chart of Crystal Reports 2008 using formulas or parametesr or any other idea?? Your suggestions are welcomed. Thanks Regards, Atul