From byte[] to PublicKey

Hi all,
I am storing public and private KeyPairs separately in database as byte[] using the privateKey.getEncoded() method.
My problem is that I now need to retrieve the Keys, which are in a byte[]. Is it possible to return them to there original Public and Private keys??
Any help would be greatly apprieciated, as I am new to Cryptography.
Many Thanks,
Stephen.

Thanks for your help Grant.
Here is the code for anyone else how may have the same problem:
// st is the byte[]
KeyFactory kf = KeyFactory.getInstance("RSA", "BC");
PKCS8EncodedKeySpec encodedKey = new PKCS8EncodedKeySpec(st);
PrivateKey key = kf.generatePrivate(encodedKey);Stephen.

Similar Messages

  • NLS_LENGTH_SEMENTICS from BYTE TO CHAR

    Hi,
    For supporting multibyte character, we need to change NLS_LENGTH_SEMENTICS parameter from BYTE to CHAR. But this parameter setting will effect for new database tables created thereafter. To change the storage characteristics for existing database tables we explicitly executed Alter statements for database tables for columns having datatype as “Varchar2” and “Char”.
    Problem:
    ======
    Since the number of database tables in PRODUCTION are very high and contains approx. 600 million of records spread over 400 database tables, we are not in a position to afford the time which will be spent in altering these database tables in PRODUCTION.
    We ran the test by alter script in System Test environment and alteration of database tables covering 150 tables and 200 million of records was carried out in almost 16-20 hrs.
    APPROACHES WE HAVE IN MIND
    ==========================
    1. Alter all the table columns (We tried the same and taking too much time)
    2. Export /Import with NLS_LENGTH_SEMENTICS set as CHAR(We discuss with our DBA about this approach and found that it will also take too much time and there is RISK of data inconsistency)
    3. Drop the index of the table, run alter script for changing storage type BYTE to CHAR , and rebuild the index (this is also taking too much time).
    All above approaches are very costly in terms of time, that we cannot afford.
    If any one having better solution then please suggest.
    thanks in advance
    Syed

    Hi
    We are also facing a similar problem
    We ran alter table scripts and now compiling the objects
    and that is taking lot of time.
    we have around 4000 invalids that by parallel recomp came down to 2000 but still these 2000 which are mostly packages .. are giving a hard time.
    if anyone has faced/found a similar issue/solution pls post. or maildirectly to me.
    Sunil Choudhary

  • Coversion from byte stream to character & character to byte stream.

    This is a test program.
    import java.io.*;
    class Test
         public static void main(String[] args)
              System.out.println("Hello World!");
              try
                   BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("C:/javafiles/testing/Picture.jpg"))));
                   PrintWriter bw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(new File("C:/javafiles/testing/Copy.jpg"))));
                   String in = br.readLine();
                   while (in != null)
                        bw.println(in);
                        in = br.readLine();
                   br.close();
                   bw.close();
              catch (Exception e)
                   System.out.println("\n\n**********Exception Occured**************\n" + e);
    **First of all I read jpg file convert it into character stream from byte stream.
    **and copy it back and convert it back into byte steam from character stream.
    **The file copied back is corrupted.(getting open but display has fully scattered.)
    **That means data has been lost in conversion.
    **is it due to the encoding, I havn't specified while writing, or it always happens when we convert from byte stream to character and vice versa.
    **What encoding should I use while writing jpg files.
    please comment.

    **First of all I read jpg file convert it into
    character stream from byte stream.
    **and copy it back and convert it back into byte
    steam from character stream.First of all this operation is meaningless. A JPEG file doesn't contain anything that can be converted to characters. Delete the 'conversions' and all will be well.
    **What encoding should I use while writing jpg files.None. Don't use an encoding. Don't use Readers and Writers. Use InputStreams and OutputStreams only.

  • How can I get String from Bytes

    I want to get String from array of bytes but i have some trouble from byte that it's lager more than 128. How can I do ???
    Please hepl me. Thanks very much.

    This program is only to show you what the relationships are between unsigned byte, signed byte, character, and binary values. Because of the constraints that Java has, the program code is not especially clean. Run the program and see if it helps. As has been said, the character output is dependent on the encoding in use.
    Here is a sample of some of its output:
    Unsigned byte= 189 Signed byte= -67 Character= � Binary= 10111101
    Unsigned byte= 190 Signed byte= -66 Character= � Binary= 10111110
    Unsigned byte= 191 Signed byte= -65 Character= � Binary= 10111111
    Unsigned byte= 192 Signed byte= -64 Character= � Binary= 11000000
    Unsigned byte= 244 Signed byte= -12 Character= � Binary= 11110100
    Unsigned byte= 245 Signed byte= -11 Character= � Binary= 11110101
    Unsigned byte= 246 Signed byte= -10 Character= � Binary= 11110110
    public class ATest {
        public static void main(String[] args) {
            int in;
            byte by;
            String bin;
            char chr;
            for(in=0; in<256; in++) {
                // create a byte whose binary value is equal to the;
                // integer loop counter;
                by = (byte)in;
                // mask off sign extension [that I don't agree with!] and;
                // cast the resultant 8 bits to a char;
                chr = (char)(by & 0x00ff);
                // since there's no Byte.toInteger, must cast to int to get;
                // binary string and then delete unwanted portion of string;
                if(in<128) {
                    bin = Integer.toBinaryString((int)by);
                } else {
                    bin = Integer.toBinaryString((int)by).substring(24);
                // print everything;
                System.out.println(
                    "Unsigned byte= "+in+
                    " Signed byte= "+by+
                    " Character= "+chr+
                    " Binary= "+bin);
    }

  • Imageicon created from byte array gives -1 height and -1 width...

    Hi,
    when I am trying to create an imageicon object from byte arrays the length and width of the object are coming to be -1.So I am unable to resize the image..
    This is happening for only few images, most of them are working fine and I can resize it...
    What possibly could be wrong??
    ImageIcon imageIcon = new ImageIcon(pImageData) where pImageData is bytearray..
    but I am getting imageIcon.getIconWidth()=-1
    and
    imageIcon.getIconHeight()=-1
    Can anyone help???

    es5f2000 wrote:
    I'm not sure if this is related, but I believe that images which are not currently being rendered return -1, -1 as their size.It is not even correct, so I'm confident it is not related.
    import java.awt.Image;
    import javax.swing.ImageIcon;
    import javax.imageio.ImageIO;
    import java.net.URL;
    class TestIconSize {
         public static void main(String[] args) throws Exception {
              Image image = ImageIO.read( new URL(
                   "http://forums.sun.com/im/silver-star.gif") );
              ImageIcon imageIcon = new ImageIcon( image );
              System.out.println( "Width: " + imageIcon.getIconWidth() );
              System.out.println( "Height: " + imageIcon.getIconHeight() );
    }Output.
    andrew@pc1:/media/disk/projects/numbered/all$ java TestIconSize
    Width: 16
    Height: 16
    andrew@pc1:/media/disk/projects/numbered/all$ The post after yours seems of even more dubious quality. For those (and other) reasons, I second Darryl's call for an SSCCE.

  • [svn] 4525: Fix loading RSLs from applications loaded from bytes.

    Revision: 4525
    Author: [email protected]
    Date: 2009-01-14 10:15:45 -0800 (Wed, 14 Jan 2009)
    Log Message:
    Fix loading RSLs from applications loaded from bytes.
    QE Notes: None
    Doc Notes: None
    Bugs: SDK-18250
    Reviewer: Alex
    tests: checkintests
    SystemManager.as
    Normalize the root urls passed into the RSLItems.
    LoaderUtil.as
    Test rootURL first before all the url tests. No need to perform all url tests if rootURL is null.
    Ticket Links:
    http://bugs.adobe.com/jira/browse/SDK-18250
    Modified Paths:
    flex/sdk/branches/3.3.0/frameworks/projects/framework/src/mx/managers/SystemManager.as
    flex/sdk/branches/3.3.0/frameworks/projects/framework/src/mx/utils/LoaderUtil.as

    Revision: 4525
    Author: [email protected]
    Date: 2009-01-14 10:15:45 -0800 (Wed, 14 Jan 2009)
    Log Message:
    Fix loading RSLs from applications loaded from bytes.
    QE Notes: None
    Doc Notes: None
    Bugs: SDK-18250
    Reviewer: Alex
    tests: checkintests
    SystemManager.as
    Normalize the root urls passed into the RSLItems.
    LoaderUtil.as
    Test rootURL first before all the url tests. No need to perform all url tests if rootURL is null.
    Ticket Links:
    http://bugs.adobe.com/jira/browse/SDK-18250
    Modified Paths:
    flex/sdk/branches/3.3.0/frameworks/projects/framework/src/mx/managers/SystemManager.as
    flex/sdk/branches/3.3.0/frameworks/projects/framework/src/mx/utils/LoaderUtil.as

  • Loading class from byte[]

    Hi,
    is there a way to load class (create object) from byte[] ?

    Yes. Look at ClassLoader. You will have to write your own subclass though many exist in other packages.

  • How Do I Load An Animated GIF Into PictureBox Control From Byte Array?

    I'm having a problem with loading an animated GIF int a picturebox control in a C# program after it has been converted to a base64 string, then converted to a byte array, then written to binary, then converted to a base64 string again, then converted to
    a byte array, then loaded into a memory stream and finally into a picturebox control.
    Here's the step-by-step code I've written:
    1. First I open an animated GIF from a file and load it directly into a picturebox control. It animates just fine.
    2. Next I convert the image in the picturebox control (pbTitlePageImage) to a base64 string as shown in the code below:
                    if (pbTitlePageImage.Image != null)
                        string Image2BConverted;
                        using (Bitmap bm = new Bitmap(pbTitlePageImage.Image))
                            using (MemoryStream ms = new MemoryStream())
                                bm.Save(ms, ImageFormat.Jpeg);
                                Image2BConverted = Convert.ToBase64String(ms.ToArray());
                                GameInfo.TitlePageImage = Image2BConverted;
                                ms.Close();
                                GameInfo.TitlePageImagePresent = true;
                                ProjectNeedsSaving = true;
    3. Then I write the base64 string to a binary file using FileStream and BinaryWriter.
    4. Next I get the image from the binary file using FileStream and BinaryReader and assign it to a string variable. It is now a base64 string again.
    5. Next I load the base64 string into a byte array, then I load it into StreamReader and finally into the picturebox control (pbGameImages) as shown in the code below:
    byte[] TitlePageImageBuffer = Convert.FromBase64String(GameInfo.TitlePageImage);
                            MemoryStream memTitlePageImageStream = new MemoryStream(TitlePageImageBuffer, 0, TitlePageImageBuffer.Length);
                            memTitlePageImageStream.Write(TitlePageImageBuffer, 0, TitlePageImageBuffer.Length);
                            memTitlePageImageStream.Position = 0;
                            pbGameImages.Image = Image.FromStream(memTitlePageImageStream, true);
                            memTitlePageImageStream.Close();
                            memTitlePageImageStream = null;
                            TitlePageImageBuffer = null;
    This step-by-step will work with all image file types except animated GIFs (standard GIFs work fine). It looks like it's just taking one frame from the animation and loading it into the picturebox. I need to be able to load the entire animation. Does any of
    the code above cause the animation to be lost? Any ideas?

    There is an ImageAnimator so you may not need to use byte array instead.
    ImageAnimator.Animate Method
    http://msdn.microsoft.com/en-us/library/system.drawing.imageanimator.animate(v=vs.110).aspx
    chanmm
    chanmm

  • Help needed in understanding conversion alghorithm from byte to hex

    Hi, I'm studying the following code:
    public static char[] byteToHex(byte[] data) {
      char[] retValue = new char[data.length * 2];
      int value = 0;
      int highIndex = 0;
      int lowIndex = 0;
      for (int i = 0; i < retValue.length; i++) {
        value = (data[i] + 256) % 256;
        highIndex = value >> 4;
        lowIndex = value & 0x0f;
        retValue[i * 2 + 0] = hexTable[highIndex];
        retValue[i * 2 + 1] = hexTable[lowIndex];
      return retValue;
    }There are few things (the most important) which I don't understand about the above code.
    I understood that what's returned has got double size related to what's passed in because a char takes 16 bits while a byte takes 8.
    1) I don't understand why each byte must be first added 256 and then % with 256 (returning the same value - Is this to eliminate negative values?)
    2) I do understand that each byte is transformed in two hexadecimal values: one is the highIndex (first 8 bits) and the second is the lowerIndex (last 8 bits) and that each value is tranformed in its hexadecimal value from the array of hex values.
    3) What I don't really understand is why the highIndex is calculated as: value >> 4
    and the lowest index is calculated as value 0x0f (is this last also to eliminate negative values?)
    If someone could clarify this for me, I'd be very grateful.
    Thanks.
    Marco

    So, does this mean that we add 256 to eliminate the sign?No. You need the whole line to convert a signed byte into an int between 0 and 255.
    A simpler way to do this would be
    value = data[i] & 0xFF;
    This moves down the higher bits so that it turnsinto lower bits. i.e. we need it to >be between 0 and
    15.
    Is this shifted of 4 because Math.pow(2, 4) = 16.0?Doing in this case, x >>4 is the same as x / 16
    This leaves only the lowest 4 bits.Is the following what happens?There are no char values produced. Using 0000 as an example is not a good idea as you can change it in many ways and it is still 0000
    >
    Received as initial value:
    byte: 0000 0000
    What we need to obtain:
    char: 0000 0000 0000 0000
    The first 4 bits of the above byte are shifted of 4
    positions to find the hexadecimal equivalent (if from
    2 I want to get to 16 I have to do the opposite of
    powering a number by 4); The last four bits of the
    byte are extracted because of the '&' operator with
    0x0f (which in binary is 1111 - Therefore all the '1'
    are kept)?Yes.

  • Create image from byte[]array on server side

    Hello everyone..
    I'm developing an application which will take snapshots from a mobile device, and send it to my pc via bluetooth. I have my own midlet which uses the phone camera to take the snapshot, i want to transfer that snapshot to my pc.
    The snapshot is taken is stored in an array byte.
    The image can be created on the phone itself with no problem using : image.createImage(byte[])
    my problem is that when i send the array byte via bluetooth, and receive it on the server, i cannot create the image using the :image.createImage() code
    The connection is good since i have tested by writing the content of the array in a text file.
    Piece of midlet code:
                try{
                     stream = (StreamConnection)Connector.open(url);
                     OutputStream ggt = stream.openOutputStream();
                     ggt.write(str);
                     ggt.close();
                }catch(Exception e){
                     err1  = e.getMessage();
                }where str is my array byte containing the snapshot
    And on my server side:
    Thread th = new Thread(){
                   public void run(){
                        try{
                             while(true){
                                  byte[] b = new byte[in.read()];
                                  int x=0;
                                  System.out.println("reading");
                                  r = in.read(b,0,b.length);
                                  if (r!=0){
                                       System.out.println(r);     
                                       img = Image.createImage(b, 0, r);
                                                            //other codes
                                       i get this error message:
    Exception in thread "Thread-0" java.lang.UnsatisfiedLinkError: javax.microedition.lcdui.ImmutableImage.decodeImage([BII)V
         at javax.microedition.lcdui.ImmutableImage.decodeImage(Native Method)
         at javax.microedition.lcdui.ImmutableImage.<init>(Image.java:906)
         at javax.microedition.lcdui.Image.createImage(Image.java:367)
         at picserv2$1.run(picserv2.java:70)
    Please anyone can help me here? is this the way to create the image on the server side? thx a lot

    here is exactly how i did it :
    while(true){
                                  byte[] b = new byte[in.read()];
                                  System.out.println("reading");
                                  r = in.read(b, 0, b.length);
                                  if (r!=0){
                                       Toolkit toolkit = Toolkit.getDefaultToolkit();
                                       Image img = toolkit.createImage(b, 0, b.length);
                                       JLabel label = new JLabel(new ImageIcon(img) );
                                       BufferedImage bImage = new BufferedImage(img.getWidth(label),img.getHeight(label),BufferedImage.TYPE_INT_RGB);
                                       bImage.createGraphics().drawImage(img, 0,0,null);
                                       File xd = new File("D:/file.jpg");
                                       ImageIO.write(bImage, "jpg", xd);
                                       System.out.println("image sent");
                             }Edited by: jin_a on Mar 22, 2008 9:58 AM

  • How can I create Icon from byte[]

    I have such kind of task: program gets byte[] from DB (it's a *.png image bytes), after that I need to recreate icon from this bytes.
    Oleg.

    You could write the bytes to a temporary png file and load it with an ImageIcon. I'm not sure if ImageIcon handles png though...

  • Video playback from byte[]

    Hello all,
    I'm currently buidling an app to display MMS messages on the desktop. To this end, I have a framework which contains audio and video components in byte[]. I already managed to play the audio from a byte[], but I can't figure out how to do the same with a byte[] containing a video.
    Any help would be appreciated.
    Mark

    This is what abrody has to say on the subject.
    Yes, but only at 720 x 480 resolution. Some TVs offer higher resolutions and DVI ports where you can do a DVI to DVI connection. And actually there was a dongle which came with your Powerbook which supports S-Video via its S-Video port.
    Cheers Don

  • Re-construct the key from byte[]

    Hi,
    I am constructing the key as follows:
    KeyGenerator keyGenerator = KeyGenerator.getInstance("Blowfish");
    keyGenerator.init(128);     
    Key key = keyGenerator.generateKey();
    I intend to use this key for Encryption/Decryption etc. Then, I am getting the byte[] of the key as follows:
    byte[] keyBytes = key.getEncoded();
    Now, it there any way to re-construct they original key from keyBytes.
    Any help in on this is highly appreciated.
    Thanks,
    Ajas.

    OK...
    I found the way...
    try {
    // Generate a key
    KeyGenerator keyGen = KeyGenerator.getInstance("DESede");
    SecretKey key = keyGen.generateKey();
    // Get the bytes of the key
    byte[] keyBytes = key.getEncoded();
    int numBytes = keyBytes.length;
    // The bytes can be converted back to a SecretKey
    SecretKey key2 = new SecretKeySpec(keyBytes, "DESede");
    boolean b = key.equals(key2); // true
    } catch (NoSuchAlgorithmException e) {

  • Change NLS_LENGTH_SEMANTICS from BYTE to CHAR on Oracle 9i2 problem!

    Hi,
    I have created a new database on Oracle 9i 2, I did not find the correct pfile parameter for the NLS_LENGTH_SEMANTICS setting.
    So have created a standart UTF8 database and now I am trying to change the standard NLS_LENGTH_SEMANTICS=BYTE to CHAR. When I execute the following command in SQL PLUS "ALTER SYSTEM SET NLS_LENGTH_SEMANTICS=CHAR SCOPE=BOTH"
    The system is tells me that command is successfully executed.
    But when I look at the NLS_DATABASE_PARAMETERS table I do not see any change for the NLS_LENGTH_SEMANTICS parameter.
    I have also restarted the instance but still everything is the same as it was before.
    Do you know what I am doing wrong?
    Regards
    RobH

    Hi,
    Yeah you are right, the nls_session_parameters "NLS_LENGTH_SEMANTICS" for the app user is set to CHAR.
    This means that NLS_DATABASE_PARAMETERS is from the SYS or SYSTEM user view?
    Thanks a lot
    Regards
    RobH

  • Displaying Image from byte[ ]

    I am using Webservice for data control and ADF UI (Jdev 11.1.1.3)
    I need to display image on jsff using the byte[] I receive from web service which fetches data from BLOB column in DB. Is there any way apart from ImageServlet because I am not allowed to access DB.
    Thanks in advance. Amit

    ImageServlet doesn't mean that you need to access data from DB. af:image needs a source, so ImageServlet acts as source for this, the implementation of data retrieval can be modified as per your use case.

Maybe you are looking for

  • UCM-VCR Adapter in WLP error while publishing content-config.xml changes

    Hi, I am getting this error when i publish my changes to server for UCM-VCR Adapter in WLP 10.3.2. weblogic.application.ModuleException: Error reading descriptor: META-INF/content -config.xml for app module ucmEAR at weblogic.application.config.Defau

  • Need Mini 110 BIOS (binary version)

    Hi, I'm hoping someone from HP is monitoring this forum and is willing to assist.  I'm attempting to repair a Mini 110 (VF704AV, mobo #579568-001) for a friend of mine who, after attempting to upgrade the machine, could no longer get past the HP logo

  • Error in Chinese language translation In Forms....

    We have our application based on Oracle and d2k. Standard language is English. Thus all the labels and data in the Form and in the Tables are in english language. Now we wish to generate one of the forms in chinese language which will change the labe

  • Quirky Magic Mouse Behavior

    I'm having trouble with quirky behavior of a Magic Mouse that's being used with an Intel iMac. In the Mouse panel of System Preferences I have the "Two Finders" option of "Left/Right to Navigate" set on. When in a Finder window set to "list" view I f

  • Hide field in material master

    Hi Friends, I want to hide a field in material master can some please give the step by step method of how to do the same. Regards, Wasim.