I want to use my key that is a BigIntegar in aes encryption

Random rand = new Random();
BigInteger secretKey= new BigInteger(1024,3,rand) ;
Cipher aesCipher = Cipher.getInstance("AES");
aesCipher.init(Cipher.ENCRYPT_MODE,secretKey);

The two methods that i used to create the secretkey are
//that is member variables in the class server
public SecretKey secretKey;
public PublicKey publicKey;
public KeyAgreement ka ;
public static String genDhParams() {
try {
// Create the parameter generator for a 1024-bit DH key pair
AlgorithmParameterGenerator paramGen = AlgorithmParameterGenerator.getInstance("DH");
paramGen.init(1024);
// Generate the parameters
AlgorithmParameters params = paramGen.generateParameters();
DHParameterSpec dhSpec
= (DHParameterSpec)params.getParameterSpec(DHParameterSpec.class);
// Return the three values in a string
return ""+dhSpec.getP()+","+dhSpec.getG()+","+dhSpec.getL();
} catch (NoSuchAlgorithmException e) {
} catch (InvalidParameterSpecException e) {
return null;
The second method is:
private void keyExchange()throws IOException
setTextFieldEditable( true );
// Retrieve the prime, base, and private value forgenerating the key pair.
// If the values are encoded as in
// Generating a Parameter Set for the Diffie-Hellman Key Agreement Algorithm,
// the following code will extract the values
String[] values = genDhParams().split(",");
BigInteger p = new BigInteger(values[0]);
BigInteger g = new BigInteger(values[1]);
int l = Integer.parseInt(values[2]);
try {
// Use the values to generate a key pair
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH");
DHParameterSpec dhSpec = new DHParameterSpec(p, g, l);
keyGen.initialize(dhSpec);
KeyPair keypair = keyGen.generateKeyPair();
// Get the generated public and private keys
PrivateKey privateKey = keypair.getPrivate();
publicKey = keypair.getPublic();
// Send the public key bytes to the other party..
byte[] publicKeyBytes = publicKey.getEncoded();
try // send publicKeyBytes to client
output.writeObject( publicKeyBytes );
output.flush(); // flush output to client
} // end try
catch ( IOException ioException )
displayArea.append( "\nError writing object" );
} // end catch
// Retrieve the public key bytes of the other party
try // read publicKeyBytes
publicKeyBytes = (byte[]) input.readObject(); } // end try
catch ( ClassNotFoundException classNotFoundException )
displayMessage( "\nUnknown object type received" );
} // end catch
// Convert the public key bytes into a PublicKey object
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(publicKeyBytes);
KeyFactory keyFact = KeyFactory.getInstance("DH");
publicKey = keyFact.generatePublic(x509KeySpec);
// Prepare to generate the secret key with the private key and public key of the other party
KeyAgreement ka = KeyAgreement.getInstance("DH");
ka.init(privateKey);
ka.doPhase(publicKey, true);
// Generate the secret key
secretKey = ka.generateSecret("AES");
System.out.println("the secret key is"+ secretKey);
// Use the secret key to encrypt/decrypt data;
} catch (java.security.InvalidKeyException e) {
} catch (java.security.spec.InvalidKeySpecException e) {
} catch (java.security.InvalidAlgorithmParameterException e) {
} catch (java.security.NoSuchAlgorithmException e) {
} Thanks

Similar Messages

  • HT204053 I want to use the same apple id for iTunes and iCloud...but I have both set up..my problem is I want to use the one that I use for iTunes for both

    I want to use the same apple id for iTunes and iCloud...but I have both set up..my problem is I want to use the one that I use for iTunes for both

    iForgot.com

  • HT4623 I want to use a program that needs Adobe Flash and I'M then told this device, iPad, can't use Adobe.  What does it use instead?

    I want to use a program that needs Adobe Flash and I'm then told Adobe Flash cannot be used with my iPad.
    What do,I use instead go Adobe Flash?

    Adobe has not made a version of Flash for the iPad.
    Kappy explains why. https://discussions.apple.com/message/19446567#19446567
    5 Flash Player Alternatives http://www.techshout.com/features/2011/01/flash-player-for-ipad-apps/
    Top 4 browsers supports flash player on iPad and iPhone
    http://mashtips.com/flash-player-ios/
     Cheers, Tom

  • Until your recent change, I used Firefox to search the internet. Nows I get a message that says "File not found." I DO NOT want to use google, but that SEEMS to be my only choice. WTF? Tell me how to get back to my Firefox search.

    I DO NOT want to use Google for anything on my computer. I do not want to search or browse using google.
    After the change Firefox made about a month ago, I can't get my search line browser, whatever the hell it is at the top of my computer screen, to give me anything. The only way I can search the internet is using google. I DO NOT want to use google for anything on my computer.
    Need more info?

    if Firefox is now searchingbrowsing through Google, I will quit Firefox and find something else. I do not want anything from Google operating on my computer.

  • What can I do if I want to use a route that is not supported by my device

    I am using a refrence trigger  Vi. and I want the source of the trigger to be Ai\ start trigger but this route is not supported by my S series DAQ device. 
    since I want the source of triggering to be one of the analog input signals that I'm acquiring by my device, I have to use a refrence trigger Vi.
    otherwise the source and destination of my triggering would be the samewhich will give me an error.
    Is there any other way I can do my triggering by my device or I need to change my device?
    Attachments:
    vi pic.jpg ‏3547 KB

    sorry. I did not attach the vi because i think you may not be able to run it. and also it has some errors in it. here's my Vi.
    Attachments:
    OFDR 10.28.2014.vi ‏51 KB

  • After a malware attack last week that rewrote my registers I had to restart from a restore point. The problem is now when firefox wants to update, it want to use the site that contains malware. I need to reset it to the proper site how do I do this?

    My son was using the cpu at the time of the first attack. He got it cleared out and working. A day later it hit again when I was using the computer. As soon as I saw the fake virus scan I brought up taskmaster and stopped it. Almost immediately it started running again so I stopped it a second time. When I did, it shut down windows explorer. The only thing that would run was the malware. I brought it up at a restore point and it ran normally. This cycle has been repeated several times.
    Both Avast and SpybotSD will find and delete the malware, and both of these update normally. I think that when firefox updates itself, it is requesting data from a malware site rater than from you. How do I reset this?

    Try this:
    #Go to '''Tools '''| '''Options '''| '''Advanced '''and click the '''Network '''tab.
    #In the Offline Storage menu, click the '''Clear Now''' button.
    #In the location bar, type '''about:config '''and hit Enter.
    #In the filter at the top, type: '''keyword.URL'''
    #Double click it and remove whatever's in there. You'll see it revert to "Default" and "String".
    #Go to File | Exit
    #Restart Firefox and go to the page you want to set as your homepage
    #Go to '''Tools '''| '''Options '''| '''General'''.
    #Make sure it says "''Show My Homepage''" in the first dropdown menu.
    #Click the button called "'''Use Current Pages'''" to set the homepage to the one you have on the screen.

  • Imac is 4 months old.  Using installed Outlook for Mac 2011 but now want to use ical so that I can start to use iCloud to sync with my Ipad2 and iPhone.  How do I move my calendar from outlook to ical on the iMac?

    This is my first attempt at using this forum so please be patient with me.  I am new to the apple world.  Bought an Imac desktop computer back in October and installed Microsoft Office for Mac 2011 because I was used to Word, Excel, Powerpoint, and outlook.  Now I am being told that I should be using ical for my calendar so that I will be better able to move to icloud for use between my Imac, Ipad2, and Iphone.
    The question is:  how do I move my calendar which is in "Outlook for Mac 2011" into ical on my Mac?  Do I have to remove the Outlook entries from the computer and reinstall them back to the same machine or can I somehow move calendar entries within the machine?  I appreciate any help I can get.  Thanks.

    I also already deleted my phone number from iMessage on my MBP.

  • If I check a website offer, then try to delete , it refuses to go. I can log out, but then every time I want to use the browser, that site comes up and refuses to go. What can I do?

    I am having a very annoying problem with some websites that take possession of the Safari browser. I cannot delete them and when I manage to quit the browser, the next time I bring up the browser this website spews its message once again. What can I do?  At the moment, it is a website called "Inovative Web Hosting", though I have had many other problems with other sites as well. Ella

      Quit Safari.
      Hold the shift key down and relaunch Safari.
    Reset Safari.
    Click Safari in the menu bar.
    From the drop down select "Reset Safari".
    Uncheck the box next to  " Remove saved names and passwords".
    Click "Reset".
    Empty Caches
    Safari > Preference > Advanced
    Checkmark the box for "Show Develop menu in menu bar".
    Develop menu will appear in the Safari menu bar.
    Click Develop and select "Empty Caches" from the dropdown.
    Turn off Extensions if any, and launch Safari.
    Safari > Preferences > Extensions

  • I wants to use windows key.....[Solved]

    Hi,
    I am looking to use global keybindings in Gnome... trying to find the right code for windows key ?
    <Super_L> ?
    Thanks
    MrG
    Last edited by Mr Green (2008-11-15 06:48:25)

    In Gconf I just put in <Super> and it worked. e.g.
    <Super><Alt>f

  • My mom gave me an ipod touch 4th gen. and i want to use facetime so that i can contact my cousins but i cannot see the icon of facetime on my screen.

    please help me

    Use Skype video via wifi. Works better that FaceTime IMPO, and you can talk to Android phones.
    Basic troubleshooting steps  
    17" 2.2GHz i7 Quad-Core MacBook Pro  8G RAM  750G HD + OCZ Vertex 3 SSD Boot HD 
    Got problems with your Apple iDevice-like iPhone, iPad or iPod touch? Try Troubleshooting 101
     In Memory of Steve Jobs 

  • I want to use an app that requires adoby flash player. Why can't I download adoby flash player on my Ipad4?

    Can I download Adoby Flash player on my Ipad4?

    IOS device do not support Flash
    However Skyfire, Photon, iSwifter, Browse2Go and Puffin Web Browser will provide limited Flash capability

  • Using access keys in inactive frames

    We are trying to make an existing website DDA compliant and want to use access keys to assist the keyboard-only user to navigate without a mouse. The site uses frames; we cannot change that as some 6000 pages are involved.
    We have implmented access keys in one of the 3 frames. This works fine in Internet Explorer and Firefox regardless of which frame you are on. However Safari does not see the access keys unless you are actually on the active frame. The thing is that we want to use the acess keys to navigate between frames.
    Is there anyway that we can get Safari to behave the same as IE and FF?

    For 1: you can try and access the af:query component and call getChildren() to see if you can get a hold of inner components (e.g. buttons). By default, the access key for the advanced mode button is not exposed.
    For 2) Same as for 1. This is not exposed and all you can do is to check if getChildren issued on the RichPanelCollection component reference allows you to access the command button and then set the access key to it
    Meanwhile I'll file an ER to make access keys generally accessible for change (which however may take time before this gets implemented)
    Frank

  • Using * this * key word?

    Hello
    I am trying to grey ONLY the box part (not label/caption) of the field/object, so am using below,
    xfa.resolveNode("VISITOR.Page1.myInfo.Name.ui.#textEdit.border.fill.color").value = "192,192,192";
    working fine,
    but, i came to know that the xfa.resolveNode is not efficient, so, i want to use this key word so i tired as below
    this.ui.#textEdit.border.fill.color.value = "192,192,192";
    but, not working!! pls help me how to get my requirement with this key word for a better PERFORMENCE.
    Thank you

    If it's coloring BOTH the caption and value, a sneaky way around this is to create 2 fields instead of the 1 field you currently have.
    1st field would be a label field
    2nd field would be in input field but with the caption turned off.
    then, just color the 2nd field.

  • How to use the data that we got after successful execution of a Bapi

    I have created a simple Webdynpro application to execute a user defined Bapi and that was executing successfully but the next step when i want to use the data that which i have retrieved from that Bapi i am facing problem.I am unable to use that particular data
    My idea is to use that data and again i want to filter that particular data which i got from the Bapi execution with out calling another Bapi
    Ex: I wrote a user defined Bapi to retrieve flight details if i enter the id of the particular airline
    Then i executed my webdynpro application and i am able to get the output
    from that output i want a particular flight details if i choose the City name i.e. the details related to that particular city which i choose

    Hi Praveen,
    Thanks for the Help,
    I am working with the same scenario which was there in the PDF sent by you but in that document it was directly allowing us to click on the output which we got after executing a Bapi, but here when i am executing i didn't know the procedure how to make use of the data which we got after execution and displaying it in other view
    can we write any code to access that particular data that we got after executing that flight scenario and do some operations on that particular fields
    thanks and regards
    Raghu

  • Using Enter key to submit a form, Attn: Didier

    Hi,
    I have an ADF form on my page and want to use Enter key to submit the form. I submit the form using a CommandLink which has a method bound to it as its action in a managed bean. I have set submitCL as the Id of this CommandLink and has set this in my form:
    <af:form defaultCommand="submitCL">
    but the Enter does not work. I'm using IE 7.0 and JDeveloper 10.1.3.2.
    Thanks in advance,
    S/\EE|)

    Hi Saeed,
    not sure if this is related or not, but I would test it with another browser as IE is not supported. See http://www.oracle.com/technology/products/jdev/htdocs/10.1.3.3/install.html#browsers
    Also, when the command button is in the header facet of a table or treeTable, the value of defaultCommand must also contain the table or treeTable ID.
    For example: <af:form defaultCommand="theTreeTableId:submitCL" ...>Regards,
    Didier.

Maybe you are looking for

  • Time Machine Backup Disk Cannot be found

    While my iMac was in sleep mode, I disconnected the power to my external, firewire time machine backup disk. The backup is a Western Digital hard drive. Now I get the error message "Your Time Machine Backup Disk Cannot be Found" I have rebooted the c

  • How to edit PPD List Illustrator CS3?

    Hi all, Recently updated a printer driver, which has resulted in a really long PPD list through which I have to scroll when I send something
 to print. I know in Quark there's a way that one can edit the list by turning off unwanted PPDs. Is this pos

  • Where can I get the source code of the jconsole in jdk1.5

    Where can I get the source code of the jconsole in jdk1.5?

  • Premiere elements 10 just started crashing cannot even create a new project

    Premiere Elements 10 (mac) all of a sudden will not do anything but open and then crash. It doesn't matter if I open an existing project or even start a new one. As soon as you name your new project and hit save it crashes. I have uninstalled and rei

  • Service Pack 1

    Somebody know the date to launch of the service pack 1 to Xcelsius 2008???