Modify to not use a random key

Can anyone help me modify this program so it doesn't use a random key? I want to decrypt the password in another program, so I don't want to have to read a key file.
I've seen some forums posts doing something similar, but so far I haven't been able to successfully change mine. I don't think it would take much.
Anyway, any help is appreciated.
James
Here's the Encrypt code:
import java.io.*;
import java.security.*;
import javax.crypto.*;
import sun.misc.*;
public class EncryptPassword
     public static void main(String args[]) throws Exception
          if(args.length<1)
               System.out.println("Usage : EncryptPassword text");
               return;
          Security.addProvider(new com.sun.crypto.provider.SunJCE());
          Key key;
          try
               ObjectInputStream in=new ObjectInputStream(new FileInputStream("des.key"));
               key=(Key)in.readObject();
               in.close();
          }      catch(FileNotFoundException fnfe)
                    KeyGenerator generator= KeyGenerator.getInstance("DES");
                    generator.init(new SecureRandom() );
                    key=generator.generateKey();
                    ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream("des.key"));
                    out.writeObject(key);
                    out.close();
          Cipher cipher=Cipher.getInstance("DES/ECB/PKCS5Padding");
          cipher.init(Cipher.ENCRYPT_MODE,key);
          String amalgam=args[0];
          for(int i=2;i<args.length;i++)
          amalgam+=" "+args;
          byte[] stringBytes=amalgam.getBytes("UTF8");
          byte[] raw=cipher.doFinal(stringBytes);
          BASE64Encoder encoder = new BASE64Encoder();
          String base64 = encoder.encode(raw);
          System.out.println(base64);
Decrypt code:
import java.io.*;
import java.security.*;
import javax.crypto.*;
import sun.misc.*;
public class DecryptPassword
     public static void main(String args[]) throws Exception
          if(args.length<1)
               System.out.println("Usage : DecryptPassword text");
               return;
          Security.addProvider(new com.sun.crypto.provider.SunJCE());
          Key key;
          try
               ObjectInputStream in=new ObjectInputStream(new FileInputStream("des.key"));
               key=(Key)in.readObject();
               in.close();
          }      catch(FileNotFoundException fnfe)
                    KeyGenerator generator= KeyGenerator.getInstance("DES");
                    generator.init(new SecureRandom() );
                    key=generator.generateKey();
                    ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream("des.key"));
                    out.writeObject(key);
                    out.close();
          Cipher cipher=Cipher.getInstance("DES/ECB/PKCS5Padding");
               cipher.init(Cipher.DECRYPT_MODE,key);
               BASE64Decoder decoder = new BASE64Decoder();
               byte[] raw = decoder.decodeBuffer(args[0]);
               byte[] stringBytes = cipher.doFinal(raw);
               String result = new String(stringBytes,"UTF8");
               System.out.println(result);
[\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

I get errors when I'm trying to use the sample code you sent. What else do I need to import to use DESKeySpec? I tried import javax.crypto.spec.DESKeySpec.*;
When I try to compile I get this:
C:\Temp\Java>javac EncryptPassword.java
EncryptPassword.java:41: cannot resolve symbol
symbol : class DESKeySpec
location: class EncryptPassword
DESKeySpec ks = new DESKeySpec(new byte[] { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF });
^
EncryptPassword.java:41: cannot resolve symbol
symbol : class DESKeySpec
location: class EncryptPassword
DESKeySpec ks = new DESKeySpec(new byte[] { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF });
^
EncryptPassword.java:41: possible loss of precision
found : int
required: byte
DESKeySpec ks = new DESKeySpec(new byte[] { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF });
^
EncryptPassword.java:41: possible loss of precision
found : int
required: byte
DESKeySpec ks = new DESKeySpec(new byte[] { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF });
^
EncryptPassword.java:41: possible loss of precision
found : int
required: byte
DESKeySpec ks = new DESKeySpec(new byte[] { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF });
^
EncryptPassword.java:41: possible loss of precision
found : int
required: byte
DESKeySpec ks = new DESKeySpec(new byte[] { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF });
^
6 errors
Thanks,
James

Similar Messages

  • When I use the Alt key and the clone tool, I get a message that I did not use the Alt key to define

    Whe I use the Alt key with the clone tool, I get a message that I have to use the Alt key to define the area to be copied. What am I doing wrong?

    I tried to check the alined box, but it would not work. I was able to check
    the Sample box, but they they give you about 5 choices to check and I have
    no  idea what they are all about. I appreciate your help.
    Dino
    In a message dated 9/18/2012 11:09:06 A.M. Eastern Daylight Time, 
    [email protected] writes:
    Re:  When I use the Alt key and the clone tool, I get a message that I did 
    not use the Alt key to define
    created by hatstead (http://forums.adobe.com/people/hatstead)  in 
    Photoshop Elements - View the full  discussion
    (http://forums.adobe.com/message/4707426#4707426)

  • I keep getting the start menu and various programmes opening when I use a series of keys when working in my accounting programme, I am not using the command key and is very frustrating me, can anyone help me?

    I keep getting the start menu and various programmes opening when I use a series of keys when working in my accounting programme, I am not using the command key and is very frustrating, can anyone help me?  I am working on a Mac OS X Version 10.6.8, just need to know if I can reprogram the keys to stop this happening?

    Safari browser and menu shortcuts:
    http://docs.info.apple.com/article.html?artnum=42951
    Mac OS X keyboard shortcuts:
    http://support.apple.com/kb/HT1343
    http://docs.info.apple.com/article.html?artnum=75459
    Changing behavious of Function Keys:
    http://support.apple.com/kb/HT3399?viewlocale=en_US
    and more useful information on keyboard shortcuts here:
    http://www.myfirstmac.com/index.php/mac/articles/mastering-keyboard-shortcuts
    How to re-map individual keys:
    http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&item_id=ukelele

  • When in email I can not use the delete key to erase a word

    When in email I can not use the delete key to erase a word.

    Yes, it does.  It is only in my email through Charter that it does not work.  I restored all keyboard shortcuts to the default, but that did not fix the problem.  I have a MacBook Air.
    I called Charter also, who said it was a Mac problem.
    Thank you.

  • I can not use the tab key to move to the next field or use the shift and tab to move to the prior field in forms.

    After updating to 7.0.1 I can not always use the tab key to move to the next field or use the shift and tab to move to the prior field in forms. This always worked in previous versions and it's much needed for my type of work. Does anyone know of a setting to activate this? If not can the Firefox developers work on this issue (please). I love Firefox but desperately need this feature to work correctly. Thanks!

    I tried in safe mode and the tab key worked just fine. I'm not sure about all web forms I've only recently updated to 7.0. The wen form I was using was for appraisal purposes and it has multiple data fields to fill in and also drop down menus to select from. Might I always have to use Firefox in safe mode to be able to utilize the tab between field feature? Thanks for your help!

  • Can you change iMessage to not use the enter key to send a message on a macbook pro?

    I'm using a mac with OS X Yosemite version 10.10.1 and I'm wondering if you can somehow change the settings of iMessage so that when you press the enter key it doesn't send the message. Thanks if you can help.

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode
    *https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes

  • FindByKey not used in ADFToyStore (buggy?)

    When working with ADF and JSP Pages, I found that using RowSetIterator.findByKey (called by DCIteratorBinding.setCurrentRowWithKey) has several issues: If called from the client side (DataForwardAction) and working in Sync Mode, it constantly throws a JBO-25020: View row of key <key> not found in <iterator> (even if the Key is taken from the currentRow !). When working in Batch Mode, I found no errors, but we decided to work in sync mode.
    Calling RowSetIterator.findByKey from the ApplicationModule finds the rows, but it seems to run the query unnecessarily (i.e., the query is performed in spite of the Row being in the default RowSetIter, and the fetch size is set to 1), just as if there was created a secondary RowSetIterator.
    Is it a coincidence that I have not found any usage of findByKey in the ADFToyStore ?

    I attempted to use this with a multi part key as follows:
    ViewObject vo = am.findViewObject("xyz1")
    Object[] myKey = new Object[]{
    "C","Description"
    Row[] findRow = vo.findByKey(findKey, -1);
    this returns one row as it should but if i do not use a complete key as follows:
    Object[] myKey = new Object[]{
    "C", null
    Row[] findRow = vo.findByKey(findKey, -1);
    it dosnt find any of the rows. Is there some other reason the null part of the key should not work in this case as it would with a entity based vo?

  • JFileChooser Multiple selection not working on Mac using apple, command key

    I am using Java 1.4 webstart on Mac machine.
    The code is :
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(2);
    fileChooser.setMultiSelectionEnabled(true);
    Once the File dialog opens I have problems in selecting random multiple files. Apple key or command key is used for random selection on Mac. When using either of these keys multiple selection is not possible. Whereas I am able to select files using the shift key by which row selection is possible.
    If this is not a bug and some code changes are to be done it would be fine if somebody can help me out in this.
    If this is a bug in Java 1.4 and is this fixed in Java 1.5?

    All EIDE / ATA (Parallel) devices (drives, opticals) allowed for two such drives or devices on one bus. The old style was "master" and "Slave" but CS is a "smart" approach, however, the master or only device must be on the end position. Also, the end connector will be black, the middle (slave) is gray.
    Eject sends signal to master
    To eject the "slave" device you use a modifier key.

  • How to use a standard library binary search if I'm not searching for a key?

    Hi all,
    I'm looking for the tidiest way to code something with maximum use of the standard libraries. I have a sorted set of ints that represent quality levels (let's call the set qualSet ). I want to find the maximum quality level (choosing only from those within qualSet ) for a limited budget. I have a method isAffordable(int) that returns boolean. So one way to find the highest affordable quality is to start at the lowest quality level, iterate through qualSet (it is sorted), and wait until the first time that isAffordable returns false. eg.
    int i=-1;
    for (int qual : qualSet) {
         if !(isAffordable(qual))
              return i;
         i++;
    }However isAffordable is a slightly complicated fn, so I'd like to use a binary search to make the process more efficient. I don't want to write the code for a binary search as that is something that should be reused, ideally from the standard libraries. So my question is what's the best way of reusing standard library code in this situation so as to not write my own binary search?
    I have a solution, but I don't find it very elegant. Here are the important classes and objects.
    //simple wrapper for an int representing quality level
    class QualityElement implements Comparable<QualityElement>
    //element to use to search for highest quality
    class HiQualFinderEl extends QualityElement {
         HiQualFinderEl(ComponentList cl) {...}
    //class that contains fair amount of data and isAffordable method
    class ComponentList {
         boolean isAffordable(int qual) {...}
    //sorted set of QualityElements
    TreeSet<QualityElement> qualSet When you create an instance of HiQualFinderEl, you pass it a reference to a ComponentList (because it has the isAffordable() method). The HiQualFinderEl.compareTo() function returns 1 or -1 depending on whether the QualityElement being compared to is affordable or not. This approach means that the binary search returns an appropriate insertion point within the list (it will never act as if it found the key).
    I don't like this because semantically the HiQualFinderEl is not really an element of the list, it's certainly not a QualityElement (but it inherits from it), and it just feels ugly! Any clever suggestions? Btw, I'm new to Java, old to C++.
    If this is unclear pls ask,
    Andy

    Thanks Peter for the reply
    Peter__Lawrey wrote:
    you are not looking for a standard binary searchI'm not using a binary search in the very common I'm searching for a particular key sense, which is the Collections.binarySearch sense. But binary searches are used in other situations as well. In this case I'm finding a local maximum of a function, I could also be solving f(x)=0... is there a nice generic way to handle other uses of binary search that anyone knows of?
    I would just copy the code from Collections.binarySearch and modify itI have this thing about reusing; just can't bring myself to do that :)
    It would be quicker and more efficient than trying to shoe horn a solution which expects a trinary result.Not sure I understand the last bit. Are you referring to my bastardised compareTo method with only two results? If so, I know, it is ugly! I don't see how it could be less efficient though???
    Thanks,
    Andy

  • How to use the windows key (super or hiper) as a keystroke modifier?

    I can associate the windows key (KeyEvent.VK_WINDOWS) as a regular key on a KeyStroke without problem.
    It can be alone or with a modifier, like CTRL+WIN
    KeyStroke.getKeyStroke( KeyEvent.VK_WINDOWS, InputEvent.CTRL_DOWN_MASK )My doubt is: Is there a way to use it as a modifier?
    In other words, is it possible to create the KeyStroke using the windows key with any other? e.g. "WIN+K"
    Thanks,
    Henrique Abreu

    Thanks a lot for the quick answer.
    Your KeyboardCommands class doesn't do it (but gives the idea), because it can only trigger an action on one key (like KeyStroke, that handles key+modifier).
    I could make big changes on it to add the functionality of triggering an event on a combination of keys, which would solve my problem.
    Although this solution is not so good because we totally give up of actions in Swing, which I mean stuff like actionMaps, InputMaps WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, etc.
    If KeyStroke class really doesn't provide this (unbelievable!), I wonder if there is a way to extend and enhance it? (or AWTKeyStroke)
    Can anyone say if its possible, before I go deep and find out that it isn't?
    Another secondary question (that I think doesn't worth a new topic), what's the META_DOWN_MASK or META_MASK? or where is this key?
    Henrique Abreu

  • In my numeric key pad I can not use the (.) dot because it has a (,) and it is not working in calculations.  What I can do?

    In my numeric key pad I can not use the decimal dot (.) because it has a (,) and this not work with decimal calculations.  What I can do?  Help ………

    IT NOT WORK IN MEXICO.  THANKS A LOT.  BEST REGARDS.  MANUEL LOPEZ
    El 6/2/2015, a las 16:50, Apple Support Communities Updates <[email protected]> escribió:
    You received a reply
    SGIII has replied to your question. You can view the full discussion in Apple Support Communities.
    In my numeric key pad I can not use the (.) dot because it has a (,) and it is not working in calculations.  What I can do?
    Correct Answer Helpful Answer
    Use the buttons above to tell SGIII and the rest of the community if this reply solved your question or helped you get closer to finding a solution.
    To reply to SGIII, go to the discussion in Apple Support Communities.
    You are receiving this email from Apple Support Communities. You can change your email preferences in your Apple Support Communities Profile.
    TM and copyright © 2014 Apple Inc. 1 Infinite Loop, MS 96-DM. Cupertino, CA 95014.
    All Rights Reserved | Privacy Policy | Terms of Use | Apple Support

  • Can EJB 3.0 beans be used with tables that do not have a primary key?

    Can a EJB 3.0 persistence bean be used with tables that do not have a primary key defined? I am building a test application based on the HowTo - Building EJB 3.0 Faces App paper posted after Openworld (schalk). The issue I am running into when trying to run the application is: Exception Description: Entity class [class com.persistence.Rpthead] has no primary key specified. Note: I get a simular error when using toplink directly.
    The tables I am binding to do not have primary keys defined. They use unique constraints to manage the table integrity.
    Is it possible to use EJB 3.0 on tables without a primary key? If not, are there plans to support this in the future?

    The spec requires a primary key Id annotation. I will take your suggestion to EJB 3.0 expert group.
    Can you also send an email to [email protected] with your requirement?
    -Debu

  • Cost component Split not transferring while costing using Spec Prc Key

    Hi Fellow CO consultants,
                                             I have come across an strange scenario in my work could you help me on it . We are using special procurement key to get the prices between cross company code costing while doing costing run the Materials which have the cost component split from KKPAN (costing without quantity structure ) we find an strange behaviour of update of the costing price .
    scenario 1:That is Using KKPAN  the FG materials are costed with fixed and variable cost and are marked (future ) but not released in the Production plant . Now while doing the CK40n at warehouse level the Cost component split is correctly picked up the receiver plant using the Spec Prc key properly the fixed and variable cost split .
    But
    Scenario 2: Using KKPAN the FG materials are  costed and then price is released and the material price is at current standard price .Now while doing the CK40N run the cost component split is not picking the variable and fixed contribution its picking up the Total price of the material .( this behavior is observed only in materials done with KKPAN other materials with quantity structure provides the variable and fixed itemization even in the current price of the material ) The prerequsite of the transfer control statergy is set as fist to check the future price for the fiscal year and next the current price of the material if no future price exist. The cost component split and the costing variant are the same .
    Appreciate your thoughts .. on helping Scenario 2 case why does the cost component split take the fixed and variable cost while the price of the material is in Current.
    regards
    GK

    Dear Prasad
    Try masking costing variant too at assignment to plant and co code.
    Rajneesh

  • HT1338 My MacBook Pro (running Leopard 10.5.8) won't allow keyboard to type an upper case 'C' using the shift key...works fine with caps lock, or, with my Typinator workaround using double-typed lower case c (not always best). Any ideas?

    My MacBook Pro keyboard won't type an upper case 'C' using the shift key... only with caps lock. Workaround has been to use Typinator by typing a double lower case c, not always the best solution. Mac is a refurbished model, which initially was fine. Apple tech helped me correct the quirk when it first appeared, but now it has returned and refuses fixes. Any ideas?

    I'm willing to bet that this has something to do with iCloud.  I've been facing a frozen computer nearly every time I go into it. 
    In Activity Monitor I have seen two programs associate with iCloud that take up about 2.5 GB of memory (I only have 4 in the computer) -- causing everything to freeze.  One of these is called "iCloud Helper" and the other one is something like "Address Book Sync helper" -- I see parts of these names in the stuff you have posted.
    I am at my wits' end with these and have written to Apple asking them to do away with these or fix them.  To get rid of the Address book sync thing I have gone into system preferences for iCloud and unchecked Contacts -- but then spontaneously it gets rechecked.  And oftentimes after I Force Quit the iCloud helper, it spontaneously turns on again.  My conclusion --- the iCloud is basically unusable.  It turns a Mac into the most useless, clogged, sluggish PC.  If this is happening to a lot of people's computers -- and I see no reason why yours or mine should be an exception -- these programs just might destroy Apple itself. 
    So -- I'm about to completely give up on iCloud, and I suspect that others will too unless this gets fixed.
    Cheers,
    Bob

  • Is there a way to download Office using my product key? Or because I bought it through my university, will it not let me?

    I bought Microsoft Office 2010 through my university.  I recently got a new computer that did not come with office or a DVD drive.  I still have the product key, but it wont let me download office from the online website when I enter the product
    key.
    Is there a way to download Office using my product key? Or because I bought it through my university, will it not let me?

    Is there a way to download Office using my product key? Or because I bought it through my university, will it not let me?
    Download it from here:
    http://office.microsoft.com/en-us/products/microsoft-office-2010-backup-FX101853122.aspx
    Thanks.
    Tony Chen
    TechNet Community Support

Maybe you are looking for