How to decrypt AES using a key

The example here will Generate the secret key specs first.
http://java.sun.com/developer/technicalArticles/Security/AES/AES_v1.html
I already have a Decrypt Key used in my server application. How can I use that key to decrypt the msg sent from server?

Hi
I wrote this code to check Java encryption with AES and a key. This worked fine for me. Please have a look.
Encrypt and decrypt using the DES private key algorithm
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public class AESEncrypt {
    public static void main (String[] args) throws Exception {
        Security.addProvider(new BouncyCastleProvider());
        byte[] plainText = "LOGIN=2222=v2-0-b7=SMST=smst=ASI".getBytes("utf-8");
        // Get a DES private key
        System.out.println( "\nAES key" );
        String strKey = "75de8a33d3f18f1c29d86fa42b1894c7";
        byte[] keyBytes = hexToBytes(strKey);
        // skeyspec is the key to encrypt and decrypt
        SecretKeySpec skeySpec = new SecretKeySpec(keyBytes, "AES");
        System.out.println("Key: " + asHex(key.getEncoded()));
        System.out.println( "Finish generating AES key" );
        // Creates the DES Cipher object (specifying the algorithm, mode, and padding).
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding");
        // Print the provider information
        System.out.println( "\n" + cipher.getProvider().getInfo() );
        System.out.println( "\nStart encryption" );
        // Initializes the Cipher object.
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
        // Encrypt the plaintext using the public key
        byte[] cipherText = cipher.doFinal(plainText);
        System.out.println( "Finish encryption: cipherText: " + asHex(cipherText));
        System.out.println( "\nStart decryption" );
        // Initializes the Cipher object.
        cipher.init(Cipher.DECRYPT_MODE, skeySpec);
        // Decrypt the ciphertext using the same key
        byte[] newPlainText = cipher.doFinal(cipherText);
        System.out.println( "Finish decryption: " );
        System.out.print( asHex(newPlainText) );
    public static String asHex (byte buf[]) {
      StringBuffer strbuf = new StringBuffer(buf.length * 2);
      int i;
      for (i = 0; i < buf.length; i++) {
       if (((int) buf[i] & 0xff) < 0x10)
         strbuf.append("0");
       strbuf.append(Long.toString((int) buf[i] & 0xff, 16));
      return strbuf.toString();
    public static byte[] hexToBytes(char[] hex) {
        int length = hex.length / 2;
        byte[] raw = new byte[length];
        for (int i = 0; i < length; i++) {
            int high = Character.digit(hex[i * 2], 16);
            int low = Character.digit(hex[i * 2 + 1], 16);
            int value = (high << 4) | low;
            if (value > 127) value -= 256;
            raw[i] = (byte)value;
        return raw;
    public static byte[] hexToBytes(String hex) {
        return hexToBytes(hex.toCharArray());
}

Similar Messages

  • How to trigger button using shortcut keys

    Hi Friends i want to trigger a button in java swings using keyboard keys.
    for ex: a button called "Enter" either i click mouse or i press ALT+E to trigger it.
    Plz give me sample coding if u have
    By
    vinod

    Try looking at the tutorials...
    http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html

  • How to import and use a *.key file

    Hi I've been looking for the forum a solution for this but I haven't found,
    I need to sign a file, with a private key, but the private key is a file AAA01_0408021316S.key,
    how can I load this file in order to use it to sing a document
    hope someone can help me

    http://demo.quietlyscheming.com/source/SuperImage.zip
    this is the source code, but where do i need to put it?

  • How to install Vista using product key from bottom of Satellite P200?

    Hello all,
    I recently had to replace my HDD as my P200 had a fatal error, corrupting all data on the old HDD. I have no recovery discs at all, (None were supplied), and wondered how i am supposed to re-install Vista using my product key from the bottom of the laptop? Can anybody give any kind of assistance please?
    As i have been reading other related threads i get the impression that i need to approach Toshiba and buy a recovery CD, at my expense. Is this correct?
    Thanks
    Lee

    Hi
    As far as I know the serial key which is placed at the bottom of the unit would not work with other Vista versions! the key belongs to the OEM Vista version preinstalled by Toshiba.
    As mentioned by Jeka, you will need to order an recovery disk or will need to use an clean Vista CD with an own serial key purchased previously.
    Greets

  • How do I fade using Chroma-key?

    In Final Cut Pro X, I am having some trouble fading up from black to a keyed scene.
    Here is the situation. I have my subject sitting at a table in front of a green screen. The Chroma Keyer in FCPX works great, and I am able to put my image on the timeline and set up the key how I want. The problem that I am running into is that when I add a fade from black on the video, the background image does not fade up with the keyed video.
    I have attempted several variations, and the best solution that I have found thus far is to simply set keyframes and ramp the opacity from 0-100 over a few seconds. This still causes a problem where the background image fades up  over the video during the fade, but it is the best thing I have come up with so far.

    I'm just learning FCP X (using the Trial) but I can tell you that to do this in FCP7 you had to nest the two clips. In other words, you had to take the green screen clip and the background you were compositing it over, nest them so that FCP considered it one clip, then apply the fade or transition to that.
    I can't tell you how that translates into FCP X, but I would look for a similar concept - combine the two clips and apply the fade to the combined clip. Surely it's possible though.
    Hope this helps

  • Generating AES 256 bit key using seed

    Hi
    As part of encryption requirements for encrypting the body of the SOAP Message while calling an external Web Service, it is requried to encrypt using a shared symmetric key.
    First step is to create a password digest
    Base64(sha1(nonce + createdTimestamp + password)) - This step is working completely fine and produces a 160 bit Hash
    The next step is to generate an AES 256 bit key using the above hash as the Seed. This should generate a 256 bit encrytpion key which can then be used to encrypt the message body.
    Would appreciate if anyone who knows how to generate AES 256 bit key using a hash seed in Java (v1.4.2) can provide some guidance.
    P:S. I am using WSS4J API to use WS-Security

    I have to generate 256-bit AES key with a 128-bit IV using the above password digest and the IV used for in the creation of the AES key prefixes the cipher text.
    The external WebService is .net webservice.
    Edited by: GUPTAG on Nov 25, 2008 3:05 AM

  • How Encrypt a File Using Key?

    Hi Guys,
    Here is my problem. I have to create a bank's document encrypted to send to a legacy system. ( Using a KEY to validate the roll process)
    I'm thinking to use two scenarios:
    1 - Generate the file via ABAP and sent it to a folder in a server to be consuming - SAP ERP.
    2 - Generate the file via ABAP, sent it to PI encrypt it via Java Mapping and sent it to a server.
    ABAP
    First question.
    There is a way to generate this file using SHA1 using a Key as parameter?
    (CALCULATE_HASH_FOR_CHAR)
    Second one.
    How can I decrypt this file to test?
    Third.
    There is others ways to encrypt a file via SAP ERP? UTF-8 and BASE32 are not encrypt codes. They are encoding code.
    PI
    First
    There is a library or other way to encrypt a file without implement a Java Mapping?
    Tnks.

    > There is a way to generate this file using SHA1 using a Key as parameter?
    Why don't you simple search the forum with "SHA1" term, you'd get the answer in an instant
    > How can I decrypt this file to test?
    > There is others ways to encrypt a file via SAP ERP? UTF-8 and BASE32 are not encrypt codes. They are encoding code.
    What encryption do you need?
    > But I would like to know if are these methods algorithms as DES, AES, RSA... or others ?
    Couldn't you say it at the beginning!
    By simply looking at CL_HARD_WIRED_ENCRYPTOR methods, we see that the encryption mechanism is very simple (I'm not expert so I can't tell what it is), I wouldn't rely on it...
    I recommend you to read [Note 662340 - SSF Encryption Using the SAPCryptolib|http://service.sap.com/sap/support/notes/662340]. There are also some documentation, security guides on sap library and sap marketplace.
    Edited by: Sandra Rossi on Jul 13, 2010 6:51 PM

  • How to decrypt data when you can't get the private key in Windows?

    I'm very confuse. My english is poor, but I try to say my question clearly.
    When browser connects to a https website which needs client certificate to authenticate the identity, the browser will send client certificate to web server.
    Then the web server will use the certificate to encrypt some data and send it to browser.
    Then broswer should have private key to decrypt that.
    But as I know, if I install a pfx format personal certificate, I can set can't export private key, which means you can't get the private key to use it. So how can
    the browser decrypt the data without private key?
    By the way, what is CSP, use CSP's interface can we use CryptoAPI
    to decrypt data without private key?

    Answer for question is  "you cant".. 
    "How to decrypt data when you can't get the private key in Windows?"
    Read more 
    http://msdn.microsoft.com/en-us/library/windows/desktop/aa387460(v=vs.85).aspx
    http://msdn.microsoft.com/en-us/library/windows/desktop/bb427432(v=vs.85).aspx
    http://technet.microsoft.com/en-us/library/dd277320.aspx
    http://en.wikipedia.org/wiki/Public-key_cryptography

  • How about use partial key to loop at a hashed table?

    Such as I want to loop a Internal table of BSID according to BKPF.
    data itab_bsid type hashed table of BSID with unique key bukrs belnr gjahr buzid.
    Loop at itab_bsid where bukrs = wa_bkpf-bukrs
                              and    belnr  = wa_bkpf-belnr
                              and    gjahr  = wa_bkpf-gjahr.
    endloop.
    I know if you use all key to access this hashed table ,it is certainly quick, and my question is when i use partial key of this internal hashed table to loop it, how about its performance.
    Another question is in this case(BSID have many many record) , Sorted table and Hashed table , Which is better in performance.

    You can't cast b/w data reference which l_tax is and object reference which l_o_tax_code is.
    osref is a generic object type and you store a reference to some object in it, right? So the question is: what kind of object you store there? Please note - this must be an object reference , not data reference .
    i.e
    "here goes some class
    class zcl_spfli definition.
    endclass.
    class zcl_spfli implementation.
    endclass.
    "here is an OBJECT REFERENCE for it, (so I refer to a class) i.e persistent object to table SPFLI
    data oref_spfli type ref to zcl_spfli.
    "but here I have a DATA REFERENCE (so I refer to some data object) i.e DDIC structure SPFLI
    data dref_spfli type ref to spfli.
    So my OSREF can hold only oref_spfli but it not intended for dref_spfli . That's why you get this syntax error. Once you have stored reference to zcl_spfli in osref then you will be able to dereference it and access this object's attributes.
    data: osref type osref.
    create object osref_spfli.
    osref = osref_spfli.
    "now osref holds reference to object, you can deference it
    oref_spfli ?= osref.
    osref_spfli->some_attribute = ....
    OSREFTAB is just a table whose line is of type OSREF (so can hold multiple object references - one in each line).
    Regards
    Marcin

  • How to close JFileChooser dialog only while using ESC key ?

    Hi All,
    I am using a Frame and from this frame i am calling the JFileChooser via a JButton.
    and using JFileChooser ShowOpenDialog() for open and close .
    while doing ESC operation my Main Frame is getting closed with JFileChooser dialog.
    Can i close only JFileChooser dialog while doing ESCAPE key operation.
    I Have Escape key function in Main Frame file and JFileChooser file( EscKeyEventActionIntialization)
    But while debuging i am not able to catch the esc key action inside EscKeyEventActionIntialization.
    I have attached the code, please suggest me , if i need to do any change .
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package MainPackage;
    import javax.swing.filechooser.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.KeyEvent;
    import javax.swing.*;
    public class SourceSettings extends javax.swing.JDialog{
        JDialog dialog;
        private javax.swing.JFileChooser jFileChooser1;
        MainFile  mainFile;
        ImageIcon icon = new ImageIcon(getClass().getResource("/Resource/mchpIcon.GIF"));
        /** Creates new form SourceSetting */
        public SourceSettings(MainFile  pMPFS) {
            dialog = new JDialog();
            dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            mainFile = pMPFS;
            jFileChooser1 = new javax.swing.JFileChooser();
            dialog.add(jFileChooser1);
            EscKeyEventActionIntialization();
            jFileChooser1.setDialogTitle("Browse For Folder");
            jFileChooser1.setFont(new java.awt.Font("Microsoft Sans Serif", 0, 11)); // NOI18N
            jFileChooser1.setName("Browse For Folder"); // NOI18N
        public String getDirctoryPath()
            int retval = jFileChooser1.showOpenDialog(dialog);
            dialog.setVisible(true);
            if(retval  == JFileChooser.APPROVE_OPTION)
                return jFileChooser1.getSelectedFile().getAbsolutePath().toString();
            else
                dialog.setVisible(false);
                dialog.dispose();
                return null;
        public String getParentDirctoryPath()
            return jFileChooser1.getCurrentDirectory().getAbsolutePath().toString();
        public String getOutputDirctoryPath()
            if(jFileChooser1.showOpenDialog(mainMpfs)  == JFileChooser.APPROVE_OPTION)
               return jFileChooser1.getCurrentDirectory().getAbsolutePath().toString();
            else
               dialog.dispose();
               return null;
        private void EscKeyEventActionIntialization()
            Action  ESCactionListener = new AbstractAction () {
              public void actionPerformed(ActionEvent actionEvent) {
                dialog.setVisible(false);
                dialog.dispose();
            KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, true);
            JComponent comp = dialog.getRootPane();
            comp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, "ESCAPE");
            ActionMap actionMap = comp.getActionMap();
            actionMap.put("ESCAPE", ESCactionListener);
    }

    You have a class that extends JDialog and has a JDialog member variable (very confusing), and no main(...) method. How is the class used as a JDialog?
    To get better help sooner, post a SSCCE that clearly demonstrates your problem. Note that this should be executable and should not contain any extraneous code.
    db

  • How to use Remote key for linking two repository

    Hi,
    I have a challenge like not to repeate common tables like Company_code,Currency,Vendor name,customer name across all repositories.
    Is there any way I can use 'Remote key' to link different repository.
    I can create a Main table with all common attributes required across the repository but want to know how I can connect it to different repository.
    For example to get company-code in Vendor table , how can I link Company-code main table(customized) in another repository may be thru 'Remote key'.
    Going thru java api route is not prefffered for the sake of simple solution.
    Appreciate your help in providing any idea and detail steps for the process.
    -regards, Reo

    could you confirm the name and the existence of this file "IOMM_20121213_060736.csv" ?
    same error like:
    http://www.oracle-base.com/articles/9i/external-tables-9i.php
    if the load files have not been saved in the appropriate directory the following result will be displayed.
    SQL> SELECT *
      2  FROM   countries_ext
      3  ORDER BY country_name;
    SELECT *
    ERROR at line 1:
    ORA-29913: error in executing ODCIEXTTABLEOPEN callout
    ORA-29400: data cartridge error
    KUP-04040: file Countries1.txt in EXT_TABLES not found
    ORA-06512: at "SYS.ORACLE_LOADER", line 14
    ORA-06512: at line 1Edited by: Fran on 10-ene-2013 23:32

  • Can't use down key because it opens automator. Does any one know how to disable this short cut?

    Everytime I press down on down key it opens automator. It doesn't let me delete the app. I don't know what to do, it is very frustating to fill in a chart when I can't use the down key. Does any one know how to disable this short cut?

    Are you talking about the Down Arrow key? To my knowledge there is no way to use that key as a shortcut for anything. But look in the Keyboard section of System Preferences and the Keyboard shortcut tab.

  • How to set a default value in my DropDown using the key  ?

    Hello All,
      Can someone advose how I can achieve the above ? I will like to know how to select a default value for the dropdown by key using the key value instead of description.
      The reason why I need to do so instead o fusing description is because my application will populate the dropdown using web services based on the language selection. Hence, if I were to set the default value using description, den other languages will not work anymore.
      Any help will be greatly appreciated. Thank you !!
    from
    KWok Wei

    Kwok,
    Assuming that:
    1. You have a node NodeX, where attribute TargetAttr defined
    2. You have a DropDownByKey UI control, its property selectedKey bound to NodeX.TargetAttr attribute
    Then:
    Place in your code:
    wdContext.currentNodeXElement().setTargetAttr("yourKey");
    VS
    P.S. This topic was raised several times, and forum search works good enough to find an answer

  • How to use a key file in the FTP Task using and SSL connection

    In the past I have used this code to set the FTP pass word in an FTP component task in SSIS.
    Does anyone know how to use a Key file in an SSL connection to download a file from an FTP site?  If not can you tell me where I can get the C# code examples to learn how to create a script task or if there is another way in SSIS to download large files
    from an SSL FTP site?  Thank you for any help offered.
    public void Main()
    ConnectionManager FTPConn;
    FTPConn = Dts.Connections["FTPServer"];
    FTPConn.Properties["ServerPassword"].SetValue(FTPConn, Dts.Variables["FTPPassword"].Value);
    Dts.TaskResult = (int)ScriptResults.Success;
    Antonio

    You can use SFTP for this.
    This is a way of implementing SFTP in SSIS using standard tasks 
    http://visakhm.blogspot.in/2012/12/implementing-dynamic-secure-ftp-process.html
    also see
    http://blog.goanywheremft.com/2011/10/20/sftp-ftps-secure-ftp-transfers/
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to switch off the computer using the key on the keyboard?

    Hi,
    i've been using Mountain Lion for a while on my MBPr and when I wanted to switch off my mac, I used the key on the dashboard, then it asked me whether I wanted to switch off, restart or go on sleep mode... Now though with Mavericks, this button only makes it go on sleep mode...how to change the function of this key, in order to switch the computer off instead of sleep mode or how to get the window asking me what to do back?
    Thanks,
    BadGoldEagle

    It's a laptop, and when I don't use it i put it in a case and hide it (I've been burgled several times and I don't want to lose my Mac...
    About my friend: He was using his laptop when he had to go out (groceries....) and because he was in bed, he left it under his blanket to hide it form view... he put his computer to sleep. Unfortunately, windows update noticed something needed to be updated and switched back on the computer and during the update, it became kinda hot and it burned the CPU... bad...
    You'll understand I don't want to do that to my mac...
    And now all i have to do is wait 'till Apple brings an update to fix that...

Maybe you are looking for

  • Non-factory Apps Disappearing Randomly After Upgrade to iOS 5.1

    Hi all, I've had my iPad 2 for about 9 months.  Since upgrading to iOS 5.1, on two separate occasions, I've had all but the factory apps disappear from my iPad.  This happened randomly during the day, not during or immediately following a sync.  My m

  • Export of RAW files loses EXIF data

    I am having a problem when I export files out of the PSE Organizer from RAW format to JPG that I am losing EXIF data on the resulting JPG file. I am using PSE 6 on Windows Vista and primarily manage my images in RAW format (Nikon D300 NEF) within the

  • What cable to connect 24" Dell to G5 with 800XT card?!

    Hi All, The Dell has a smaller dvi port than the Powermac with the ATI card.... is there a specific cable I need?! Any help would be very much appreciated... Jon

  • Multiple subject areas within publisher & drill downs

    Hi , can we pull data from multiple subject areas within publisher and place the report on a dashboard and still do drill downs? Thanks in advance.

  • Ignore working hours for a specific route

    Dear SAP Gurus, I'm on to maintain a route for 0 days and 0 hours. Therefore I customized a new route, and set the Delivery and Transportation Scheduling of my shipping point to "route dependent". So far, this works fine, but although I entered a tot