Trying to convert a int back to a textfield - help

Okay this is what I want. I want to type a number in a TextField and double it.... So lets say I type in 10, it will output 20.. But I cant seem to get it to work. The integer won't change it back to a textfield usable text thing .. any help? And yes, i'll admit, its for school, not really for marks, but just to learn.. Theres like 10 of them. And I've been trying to get it to work for awhile, and I ain't asking for coding, or cheating. I'm just asking for help :)
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Myname extends Applet implements ActionListener
     Button pressMe = new Button("Enter a number");
     TextField answer = new TextField(10);
     Font bigfont = new Font("TimesRoman", Font.ITALIC,24);
     public void init()
          add(pressMe);
          add(answer);
          answer.requestFocus();
          pressMe.addActionListener(this);
     public void actionPerformed(ActionEvent thisEvent)
          int doubleamount = (new Integer(answer.getText())).intValue();
          int doubleamount2 = doubleamount + doubleamount;
          answer.setText(doubleamonut2);
          invalidate();
          validate();
Thats what I have

You need a String.valueOf (doubleamount2)to convert your int to a String, and you don't need
the revalidate ().
Kind regards,
LeviYeah, Levi is correct. :-)

Similar Messages

  • Exception thrown trying to convert string to int

    Hey Guys,
    i imported a csv file into my app which i divide using the split() method and put into an array then I divided the array into variables;
    fruit = piece[0];
    price = piece[1];
    unit = piece[2];Now since price has to be a double i converted it into a double;
    price2 = Double.parseDouble(price);which worked grand
    but when i try to convert unit to an integer
    unit2 = Integer.parseInt(unit);i got error
    Exception in thread "main" java.lang.NumberFormatException: For input string: "3
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    so i tried removing white spaces as follows
    target = unit.replace(" ", "");which worked and displayed grand, then i tried converting to int again but the same exception was thrown, can anyone help me with this problem, thanks
    mark

    sorry for the messed up format previously.
    Like you said the unit.replaceAll(" ", ""); did not do the trick, when displayed as a string it looked like 3 was on its own but still did not convert to int. I assume line break or something existed in the csv file like you mentioned earlier as unit was the last word in the csv file.
    when i used unit.trim(); and tried to convert to integer it worked perfectly.
    thanks all for your help,
    Mark

  • How do you convert a Double back to a String?

    I am trying to convert a type Double back to a string so i can display the information using a g.drawstring in my applet.
    Thanks

    When i put in the value of method i still get this message
    .java:111: cannot resolve symbol
    symbol : method drawString (double,int,int)
    location: class java.awt.Graphics
              g.drawString(M,100,40);
    ^
    1 error
    Am i putting the code in the wrong area? here is part of the code where i put it in
    //output using awt
    String.valueOf(M);
         g.drawString("The Average for 7 random numbers",100,10);
         g.drawString("Minimum value:",5,25);
         g.drawString("Maximum value:",5,40);
         g.drawString("Mean value:",5,55);
         g.drawString(myMin,100,25);
              g.drawString(M,100,40);
    g.drawString(myMean,100,55);
    The value M is my value that i am processing in an array from this code ---
    mean = sum / anArray.length;
              //for loop to calculate the max value
              for(int k = 0; k < anArray.length-1 ; k++) {
                   M = anArray[k];
                   if ( M > max) {
                        max = M;
    Thanks

  • "Property value is not valid" when PropertyGridView tries to convert a string to a custom object type.

    Hi,
    I have a problem with an PropertyGrid enum property that uses a type converter.
    In general it works, but when I double clicking or using the scoll wheel,  an error message appears:
    "Property value is not valid"
    Details: "Object of type 'System.String' cannot be converted to type 'myCompany.myProject.CC_myCustomProperty."
    I noticed that the CommitValue method (in PropertyGridView.cs) tries to convert a string value to a CC_myCustomProperty object.
    Here is the code that causes the error (see line 33):
    (Using the .net symbols from the PropertyGridView.cs file)
    1
            internal bool CommitValue(GridEntry ipeCur, object value) {   
    2
    3
                Debug.WriteLineIf(CompModSwitches.DebugGridView.TraceVerbose,  "PropertyGridView:CommitValue(" + (value==null ? "null" :value.ToString()) + ")");   
    4
    5
                int propCount = ipeCur.ChildCount;  
    6
                bool capture = Edit.HookMouseDown;  
    7
                object originalValue = null;   
    8
    9
                try {   
    10
                    originalValue = ipeCur.PropertyValue;   
    11
    12
                catch {   
    13
                    // if the getter is failing, we still want to let  
    14
                    // the set happen.  
    15
    16
    17
                try {  
    18
                    try {   
    19
                        SetFlag(FlagInPropertySet, true);   
    20
    21
                        //if this propentry is enumerable, then once a value is selected from the editor,   
    22
                        //we'll want to close the drop down (like true/false).  Otherwise, if we're  
    23
                        //working with Anchor for ex., then we should be able to select different values  
    24
                        //from the editor, without having it close every time.  
    25
                        if (ipeCur != null &&   
    26
                            ipeCur.Enumerable) {  
    27
                               CloseDropDown();   
    28
    29
    30
                        try {   
    31
                            Edit.DisableMouseHook = true;  
    32
    /*** This Step fails because the commit method is trying to convert a string to myCustom objet ***/ 
    33
                            ipeCur.PropertyValue = value;   
    34
    35
                        finally {   
    36
                            Edit.DisableMouseHook = false;  
    37
                            Edit.HookMouseDown = capture;   
    38
    39
    40
                    catch (Exception ex) {   
    41
                        SetCommitError(ERROR_THROWN);  
    42
                        ShowInvalidMessage(ipeCur.PropertyLabel, value, ex);  
    43
                        return false;  
    44
    I'm stuck.
    I was wondering is there a way to work around this? Maybe extend the string converter class to accept this?
    Thanks in advance,
    Eric

     
    Hi,
    Thank you for your post!  I would suggest posting your question in one of the MS Forums,
     MSDN Forums » Windows Forms » Windows Forms General
     located here:http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=8&SiteID=1.
    Have a great day!

  • Converting an int to a string

    i want to know how to convert an int to a string .
    I have tried toString() but it says can't dereference an int.
    any ideas ????
    thanks

    What I mean by the object being null is, say for example, you have the following method:
       public String combine(Object o1, Object o2){
          return o1.toString() + o2.toString();
       }This method will throw a NullPointerException if either or both o1 and/or o2 are null. If you use it like so:
       public String combine(Object o1, Object o2){
          return String.valueOf(o1) + String.valueOf(o2);
       }This will always work. (I know someone out there would say that this would return a String like "nullnull" if both are null, and so forth and so on, but hey, you get my drift.) I'm also not saying the you can't not check if either o1 or o2 is null before proceeding, so the following also works:
       public String combine(Object o1, Object o2){
          String s = null;    // I'm using this instead of StringBuffer for
                              // simplicity's sake so don't get this wrong
          if (o1 != null){
              s = o1.toString();
          if (o2 != null){
              s += o2.toString();
          return s;
       }As you can see, there's no right or wrong way in programming as long as you achieve the result. The only thing that would matter is how clean your code is, how efficient your code is, and how maintainable your code is.

  • I am trying to convert a PDF to Word doc-- it worked previously but now it won't-?

    Trying to convert PDF to Word doc--- was able to do it  before but now nothing shows up when I click on the downloaded file

    Hi asjoseph,
    It sounds like you're reporting two different problems--is that correct? One, that you're unable to convert using ExportPDF, and another that you're trying to open or convert PDF? Is that correct?
    For the first issue, make sure that you're signed in to the ExportPDF service. You can log in directly at cloud.acrobat.com/exportpdf.
    For the second part of your question, please tell me a bit more about where that error is occurring, and what steps you're taking before the error appears.
    I look forward to hearing back from you.
    Best,
    Sara

  • I have just tried to convert a PDF file for the first time. Get error message-can't access service.

    I just purchased ExportPDF and have tried to convert a PDF file to *.docx and *.rtf for the first time.  In both cases I get a file that says there was an error is accessing the online service.  What do I do?

    Could you try these steps to alleviate the access issue you're having:
    Choose Edit > Preferences (Win) or Adobe Reader > Preferences (Mac)
    Click 'Online Services' on the left-hand side
    Sign out of our Adobe ID and sign back in.
    Try to convert your document again.
    If you continue to have trouble, please verify that you can access the service via the web interface.  To do this:
    Open a browser and navigate to http://exportpdf.acrobat.com/signin.html
    Try to log in with your Adobe ID (email address) and password
    Once logged in, follow the on-screen prompts to convert a file
    Let us know if you're still having trouble and we'll try to help!
    -David

  • Completely erased my entire file when trying to convert

    I tried to convert an .rtf file this morning, it looked like it was working then when I tried to view it the file was completely blank. So I went back and tried to open the file in my wordpad and that also is now COMPLETLY BLANK. I'm kinda ticked off about this. Is there any way to get the file back? It's there... it's just blank. So agriviated.

    Hello there,
    I'm sorry to hear you're having trouble. Unfortunately, I'm not sure I completely understand what your process was: Acrobat.com does not change the content of a file during conversion to PDF, and I do not think that the conversion server is capable of deleting content. If you wouldn't mind giving a more detailed account of the process you went through to convert your .rtf file to PDF, I will do what I can to help figure out where it went wrong. Like I said, Acrobat.com could not have erased any material, so there may be something else going on. Thank you for your patience!
    Kind regards,
    Rebecca

  • Problem when trying to convert using PDFG

    Hi,
    I'm trying to convert come files using PDFG. I tried the user console, the email account and the WebService API. None of this options worked.
    I can see in the log file that JBOSS is launched successfully, with every BMC being started without any error. The only problem that i have is taht QuartzService error but the Adobe support already told me that this was not a problem.
    When trying to submit a document for conversion, the log files registered the errors below. does anyone has some clue on this problem ?
    TIA,
    [code]
    2007-04-02 17:34:24,332 INFO [com.adobe.native2pdf.internal.DequeueBean] Retry enabled for Native conversion
    2007-04-02 17:34:24,348 INFO [com.adobe.native2pdf.internal.AESEngineBean] AES_1001: Begin processing job c27e1f-6c2951-465685-a7364b-845e2f-7ae0a1
    2007-04-02 17:34:24,566 INFO [com.adobe.service.ProcessResource] BMC505: Service WordConverterService: Starting native process with command line "C:\\Adobe\\LiveCycle\\jboss\\server\\all\\svcnative\\WordConverterService\\bin\\dll\\pdf gen.exe" PDF-WO3ff760003 -beginExecutable "C:\\Adobe\\LiveCycle\\jboss\\j2re1.4.2_04_compiler\\bin\\javaw.exe" -endExecutable -Xmx20m -cp "C:/Adobe/LiveCycle/jboss/server/all/svcnative/WordConverterService/bin/aaes-idl-bmc.jar; C:/Adobe/LiveCycle/jboss/server/all/svcnative/WordConverterService/bin/aaes-jaxb.jar;C:/Ad obe/LiveCycle/jboss/server/all/svcnative/WordConverterService/bin/adobe-bslj.jar;C:/Adobe/ LiveCycle/jboss/server/all/svcnative/WordConverterService/bin/AdobeCSA.jar;C:/Adobe/LiveCy cle/jboss/server/all/svcnative/WordConverterService/bin/AdobeCSAUtils.jar;C:/Adobe/LiveCyc le/jboss/server/all/svcnative/WordConverterService/bin/appmon.jar;C:/Adobe/LiveCycle/jboss /server/all/svcnative/WordConverterService/bin/commonbmc.jar;C:/Adobe/LiveCycle/jboss/serv er/all/svcnative/WordConverterService/bin/jaxb-api.jar;C:/Adobe/LiveCycle/jboss/server/all /svcnative/WordConverterService/bin/jaxb-impl.jar;C:/Adobe/LiveCycle/jboss/server/all/svcn ative/WordConverterService/bin/jaxb-libs.jar;C:/Adobe/LiveCycle/jboss/server/all/svcnative /WordConverterService/bin/jniw2.9.5_pdfmapi1.0.jar;C:/Adobe/LiveCycle/jboss/server/all/svc native/WordConverterService/bin/jniw2.9.5_word8.1.jar;C:/Adobe/LiveCycle/jboss/server/all/ svcnative/WordConverterService/bin/jniwrap-2.9.6.241.jar;C:/Adobe/LiveCycle/jboss/server/a ll/svcnative/WordConverterService/bin/namespace.jar;C:/Adobe/LiveCycle/jboss/server/all/sv cnative/WordConverterService/bin/winpack.jar;C:/Adobe/LiveCycle/jboss/server/all/svcnative /WordConverterService/bin/WordConverterServer.jar;C:/Adobe/LiveCycle/jboss/server/all/svcn ative/ServicesNatives2/jars/adobe-bslj.jar;C:/Adobe/LiveCycle/jboss/server/all/svcnative/S ervicesNatives2/jars/jacorb.jar" com.adobe.native2pdf.bmc.WordConverterServer -IOR IOR:000000000000002249444C3A636F6D2F61646F62652F736572766963652F4D616E616765723A312E30000 000000000020000000000000068000102000000000E3139322E3136382E31302E3130000DC8000000134A426F7 3732F42522D312F010000000000000000000000020000000000000008000000004A414300000000010000001C0 0000000000100010000000105010001000101090000000105010001000000010000002C0000000000000001000 000010000001C00000000000100010000000105010001000101090000000105010001 -AppServer jboss
    2007-04-02 17:34:24,676 INFO [STDOUT] Command line '"C:\Adobe\LiveCycle\jboss\j2re1.4.2_04_compiler\bin\javaw.exe"'
    2007-04-02 17:34:27,222 INFO [STDOUT] myOwnProcesses found 2
    2007-04-02 17:34:27,925 INFO [STDOUT] com.adobe.native2pdf.bmc.ConvertWord starting run()
    2007-04-02 17:34:28,315 INFO [STDOUT] com.adobe.native2pdf.bmc.ConvertWord calling execute
    Processing document 'C:\Documents and Settings\build_user\Local Settings\Temp\pdfg-build_user\c2\7e1f-6c2951-465685-a7364b-845e2f-7ae0a1\New Text Document.txt'
    2007-04-02 17:34:30,034 INFO [STDOUT] COM PID appears to be 5216
    2007-04-02 17:34:31,846 INFO [STDOUT] Running Word version 11.0
    2007-04-02 17:34:31,971 INFO [STDOUT] ConversionInterface returned status -2147467259

    Following the exception stack :
    Got default parameter bits 1c80017
    ConversionInterface returned status 0
    Read-Back ConversionInterface returned status 0, bits 1c00017
    JobOptions from file null
    2007-04-02 17:34:34,360 INFO [STDOUT] Working on doc New Text Document.txt
    2007-04-02 17:34:34,439 INFO [STDOUT] com.jniwrapper.win32.com.ComException: COM object method returns error code: 0x80004005; E_FAIL (Unspecified error)
    2007-04-02 17:34:34,439 INFO [STDOUT]
    at com.jniwrapper.win32.com.impl.IUnknownImpl.invokeStandardVirtualMethod(SourceFile:624)
    at com.adobe.native2pdf.internal.wrap.acrobat7.pdfmakerapilib.impl.IPDFMakerDriverImpl.execP DFMaker(IPDFMakerDriverImpl.java:94)
    at com.adobe.native2pdf.bmc.ConvertBasePDFM.execPDFMaker(ConvertBasePDFM.java:438)
    at com.adobe.native2pdf.bmc.ConvertWord.convertViaPDFMaker(ConvertWord.java:179)
    at com.adobe.native2pdf.bmc.ConvertWord.execute(ConvertWord.java:66)
    at com.adobe.native2pdf.bmc.ConvertBase.run(Con
    2007-04-02 17:34:34,439 INFO [STDOUT] vertBase.java:82)
    2007-04-02 17:34:34,439 INFO [STDOUT] at java.lang.Thread.run(Unknown Source)
    2007-04-02 17:34:35,266 INFO [STDOUT] Sleeping before oleUninitialize
    2007-04-02 17:34:36,266 INFO [STDOUT] Calling oleUninitialize
    2007-04-02 17:34:36,282 INFO [STDOUT] Calling getProcessIdsByNonDefaultWindowStation()
    getProcessIdsByNonDefaultWindowStation() found 0
    2007-04-02 17:34:36,860 INFO [com.adobe.native2pdf.internal.AESEngineBean] AES_1002: Done processing job c27e1f-6c2951-465685-a7364b-845e2f-7ae0a1
    2007-04-02 17:34:36,860 INFO [STDOUT] com.adobe.native2pdf.bmc.ConvertWord shutdown JniWrapper
    2007-04-02 17:34:36,875 INFO [com.adobe.native2pdf.internal.DequeueBean] Message queued again into job queue
    2007-04-02 17:34:36,875 INFO [com.adobe.native2pdf.internal.AESEngineBean] AES_1001: Begin processing job c27e1f-6c2951-465685-a7364b-845e2f-7ae0a1
    2007-04-02 17:34:37,094 INFO [STDOUT] com.adobe.native2pdf.bmc.ConvertWord starting run()
    com.adobe.native2pdf.bmc.ConvertWord calling execute
    Processing document 'C:\Documents and Settings\build_user\Local Settings\Temp\pdfg-build_user\c2\7e1f-6c2951-465685-a7364b-845e2f-7ae0a1\New Text Document.txt'
    2007-04-02 17:34:37,297 INFO [STDOUT] COM PID appears to be 960
    2007-04-02 17:34:37,969 INFO [STDOUT] Running Word version 11.0
    2007-04-02 17:34:37,984 INFO [STDOUT] ConversionInterface returned status -2147467259
    Got default parameter bits 1c80017
    [/code]

  • How to solve this Error?? Error_2_Cannot implicitly convert type 'int' to 'int[]'_

    Hi,
    I created a structure. It contains 1& 2 diamensional arrays. Now I want to pass values to these arrays. But at that time I got the following error.
        Error 2 Cannot implicitly convert type 'int' to 'int[]' 
            publicstructtest
              [FieldOffset(160)]
             [MarshalAs(UnmanagedType.ByValArray,
    SizeConst = 3)]
            publicint[]
    DC;
               [FieldOffset(168)]
              [MarshalAs(UnmanagedType.ByValArray,
    SizeConst = 8)]
              publicfloat[]
    IN;
               [FieldOffset(176)]
              [MarshalAs(UnmanagedType.ByValArray,
    SizeConst = 8)]
            publicbyte[,]
    us;
    privatevoidbutton1_Click(objectsender,
    EventArgse)
    //int[] T_ADC = new int[3];
                array[0].DC =12
                array[0].IN[0] = 11;
                array[0].us[0, 0] = 1;

    @DAANNIII
    >>I wrote the code as follows
    array[0].DC[0]
    =12
    but after that I got an error that  " Object reference not set to an instance of an object".Why this type of error occurs??
    Still confused about how you define variable "array[0]".
    Based on your error information, because your DC is null. As I said before, DC is an int[]. You must assign an array to DC.
    int[] array = new int[] { 2, 43 };
    test s = new test();
    s.DC = array;
    s.DC[0] = 12;//It works fine
    Best regards,
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • I am trying to convert a pdf and it asks me to sign in and then i get a network error message

    i am trying to convert a pdf and it asks me to sign in and then i get a network error message

    Hi dougtimberlake,
    We may need a little more information to go on to address the issue you're facing. Are you using ExportPDF to convert the PDF file--and from within Reader or directly via the ExportPDF website? It would also be very helpful to know the exact error message that you're receiving, and whether it happens with all the files that you try to convert, or just some. Please write back and provide a few specifics. In the meantime, please try the following:
    Clear your browser cache (steps to do this vary by browser)
    Check with your IT team to confirm if you have firewall/proxy settings that restrict the ability to upload files to the internet.
    If the issue persists after the steps above, please try another web browser.  A list of supported browsers for accessing the ExportPDF service is available here: http://www.adobe.com/acom/systemreqs/
    I look forward to hearing back from you.
    Best,
    Sara

  • Converting a byte[] back to key problem

    I CAN create a key and convert the key to a byte array, then convert the array to a string(base 64):
    KeyGenerator generator = KeyGenerator.getInstance("DES");
    generator.init(new SecureRandom());
    key = generator.generateKey();
    byte[] keyBytes = key.getEncoded;
    BASE64Encoder encoder = new BASE64Encoder();
    String randomKey = encoder.encode(keyBytes);
    and I CAN save that string to a database, forget about it, then sometime later reload it and convert it to a byte array again:
    String loadedKey = "WhAt3Ver-It-I5" //from DB
    BASE64Decoder decoder = new BASE64Decoder();
    byte[] loadedKeyBytes = decoder.decodeBuffer(loadedKey);
    what I CAN'T do is convert the loadedKeyBytes back into the key of the same type as it was originally, enabling me to decrypt whatever that key originally encrypted.
    Does anyone know.
    I know I need to convert it to a KeySpec, I presume as:
    DESKeySpec keySpec = new DESKeySpec(loadedKeyBytes);
    this compiles correctly.... but how do i then recreate the key so i can use it for decryption.
    Once i've finished this test program I should be able to port it to my application.
    Many thanks in advance guys!
    Cheers!
    Relisys
    ================ CODE FOLLOWS ======================
    import java.io.*;
    import java.security.*;
    import java.security.spec.*;
    import javax.crypto.*;
    import javax.crypto.spec.*;
    import com.sun.crypto.provider.SunJCE;
    import sun.misc.*;
    public class SecPrescrip {
    public static void main(String[] args) throws Exception {
    // Create Key.
    Key key;
    KeyGenerator generator = KeyGenerator.getInstance("DES");
    generator.init(new SecureRandom());
    key = generator.generateKey();
    // Get a cipher object
    Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
    // Encrypt the input string:
    cipher.init(Cipher.ENCRYPT_MODE, key);
    String input = "Medicare Secure Prescription: 30 Tamazopan 200mg tablets. Dosage: 1 to be taken every 4 hours";
    System.out.println("Stage 1: ENCRYPT PRESCRIPTION WITH A RANDOM DES KEY");
    System.out.println("===================================================");
    System.out.println(" - Input Plain Text: "+input);
    System.out.println("");
    byte[] stringBytes = input.getBytes("UTF8");
    byte[] raw = cipher.doFinal(stringBytes);
    BASE64Encoder encoder = new BASE64Encoder();
    String ciphertext1 = encoder.encode(raw);
    System.out.println(" - Cipher Text: "+ciphertext1);
    System.out.println("");
    byte[] keybytes = key.getEncoded();
    String randomkey = encoder.encode(keybytes);
    System.out.println(" - Random Prescription Key: "+randomkey);
    System.out.println("");
    System.out.println("ENCRYPTION SUCESSFULL");
    System.out.println("");
    System.out.println("");
    System.out.println("Stage 2: ENCRYPT RANDOM KEY WITH PATIENT MEDICARE KEY");
    System.out.println("=====================================================");
    BASE64Decoder decoder = new BASE64Decoder();
    String passphrase = "ABCD1234efghIJ56"; //Patient Medicare Key
    System.out.println(" - Patient Medicare Key: "+passphrase);
    System.out.println("");
    System.out.println(" - Input Plain Text: "+randomkey);
    String algorithm = "PBEWithMD5AndDES";
    byte[] salt = new byte[8];
    int iteration = 20;
    KeySpec ks = new PBEKeySpec(passphrase.toCharArray());
    SecretKeyFactory skf = SecretKeyFactory.getInstance(algorithm);
    SecretKey key2 = skf.generateSecret(ks);
    byte[] input2 = decoder.decodeBuffer(randomkey);
    MessageDigest md = MessageDigest.getInstance("MD5");
    md.update(passphrase.getBytes());
    md.update(input2);
    byte[] digest = md.digest();
    System.arraycopy(digest, 0, salt, 0, 8);
    AlgorithmParameterSpec aps = new PBEParameterSpec(salt, iteration);
    cipher = Cipher.getInstance(algorithm);
    cipher.init(Cipher.ENCRYPT_MODE, key2, aps);
    byte[] outputFinalKey = cipher.doFinal(input2);
    String ciphertext2 = encoder.encode(outputFinalKey);
    String saltString = encoder.encode(salt);
    String encryptedCiphertext = saltString+ciphertext2;
    System.out.println("");
    System.out.println(" - Cipher Text (Final Prescription Key): "+ciphertext2);
    System.out.println("");
    System.out.println(" - Salt: "+saltString);
    System.out.println("");
    System.out.println(" - Full Encrypted Output: "+encryptedCiphertext);
    System.out.println("");
    System.out.println("ENCRYPTION SUCESSFULL");
    System.out.println("");
    System.out.println("");
    System.out.println("Stage 3: DECRYPT PRESCRIPTION KEY USING PATIENT MEDICARE KEY");
    System.out.println("============================================================");
    //NOT CHANGED String passphrase = "ABCD1234efghIJ56";
    System.out.println(" - Patient Medicare Key: "+passphrase);
    System.out.println("");
    System.out.println(" - Input Plain Text: "+ciphertext2);
    algorithm = "PBEWithMD5AndDES";
    salt = new byte[8];
    iteration = 20;
    ks = new PBEKeySpec(passphrase.toCharArray());
    skf = SecretKeyFactory.getInstance(algorithm);
    SecretKey key3 = skf.generateSecret(ks);
    //Load in the input bytes as if they had been loaded from an sql database or the like
    String saltIn = encryptedCiphertext.substring(0,12);
    String ciphertext3 = encryptedCiphertext.substring(12,encryptedCiphertext.length());
    byte[] saltArray = decoder.decodeBuffer(saltIn);
    byte[] ciphertextarray = decoder.decodeBuffer(ciphertext3);
    aps = new PBEParameterSpec(saltArray, iteration);
    cipher = Cipher.getInstance(algorithm);
    cipher.init(Cipher.DECRYPT_MODE, key3, aps);
    byte[] outputKey2 = cipher.doFinal(ciphertextarray);
    String plaintext2 = encoder.encode(outputKey2);
    System.out.println(" - Plain Text (Random Generated Key): "+plaintext2);
    System.out.println("");
    System.out.println("");
    System.out.println("ENCRYPTION SUCESSFULL");
    System.out.println("");
    System.out.println("");
    System.out.println("Stage 4: DECRYPT PRESCRIPTION KEY USING PATIENT MEDICARE KEY");
    System.out.println("============================================================");
    // The decrypter string plaintext should be the same as the BASE64 Encoded representation of the random DES string
    byte[] randomKeyFetched = decoder.decodeBuffer(plaintext2);
    generator = KeyGenerator.getInstance("DES");
    DESKeySpec keyspec = new DESKeySpec(randomKeyFetched);
    * Stuck here! Once the key is reformed it will be complete!
    }

    You need to use a SecretKeyFactory to convert the byte array back to a SecretKey to use in decryption. Continuing your example:
    SecretKeyFactory skf = SecretKeyFactory.getInstance("DES");
    DESKeySpec desKeySpec = new DESKeySpec(loadedKeyBytes);
    SecretKey sk = skf.generateSecret(desKeySpec);
    Use sk in the call to the Cipher init() function. (Note that you don't call KeyGenerator to restore a key from its bytes.)
    Incidently, if you're using ECB mode for encryption I don't think you need to worry about the Initialization Vector. However, if you're using CBC mode (which is the default DES mode for the default SunJCE provider), I believe you also have to make sure that the decryption system starts from the same Initialization Vector that was used for encryption. To deal with this, if 'cipher' is your encryption Cipher object, then you call
    byte bytIV[] = cipher.getIV();
    to get the 8-byte IV array. To decrypt, you need to call:
    IvParameterSpec iv = new IvParameterSpec(bytIV);
    This is an AlgorithmParameterSpec, and can be used as the third argument to the init() function for Cipher to set up decryption, e.g.
    Cipher cd = Cipher.getInstance("DES/ECB/PKCS5Padding");
    cd.init(Cipher.DECRYPT_MODE, sk, iv);
    I believe that CBC mode is more secure than ECB mode when you have more than 8 bytes of material to encode (e.g. use "DES/CBC/PKCS5Padding"
    when you create the Cipher objects).
    To simplify things a bit, you might just want to use a fixed 8-byte Initialization Vector by constructing a IvParameterSpec and using it for all DES encryption and decryption.
    The documentation on all of this is extraodinarily obscure.

  • How do I handle sign in trouble when trying to convert a document?

    How do I handle sign in trouble when trying to convert a document?

    Hi jeunes781,
    Are you having trouble signing in to ExportPDF via the website, or from within Reader? If you're using Reader, make sure that you have the most current version of Reader by choosing Help > Check for Updates in the Reader application.
    If the issue occurs when you try signing in via the ExportPDF website, please clear the browser cache and try again.
    (And if neither of those work, please write back and let us know what the specific error is, and where it occurs.)
    Best,
    Sara

  • Hello, I'm trying to convert my music to mp3 Version but it says that the file is protected. Is there any way I can convert it?

    Hello, I'm trying to convert my music to mp3 Version but it says that the file is protected. Is there any way I can convert it?

    Only by burning the files to an audio CD and then ripping that back into iTunes.

  • How can I convert an int to a string?

    Hi
    How can I convert an int to a string?
    /ad87geao

    Here is some the code:
    public class GUI
        extends Applet {
      public GUI() { 
        lastValue = 5;
        String temp = Integer.toString(lastValue);
        System.out.println(temp);
        showText(temp);
      private void showText(final String text) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            tArea2.setText(text + "\n");
    }

Maybe you are looking for