Trouble encrypting correctly with AES with a static key

Hi. I'm trying to get JCE to work with the following example using AES in ECB mode (yes, ECB shouldn't be used, but it's what I'm supposed to use): given a clear text String represented by the bytes (in hex) 546578746F2070617261207465737465 and a key 6573736173656E686165686672616361, the program is supposed to provide the encrypted bytes A506A19333F306AC2C62CBE931963AE7. I used an online encryption service to check for myself if the above is true, and it is. However, I just can't get it to work right in Java:
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class AESTest {
    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 void main(String[] args) throws Exception {
        String keyString = "Texto para teste";
     // 546578746F2070617261207465737465 (Hex)
     byte[] key = keyString.getBytes("UTF-8");
     System.out.println(asHex(key).toUpperCase());
     String clearText = "essasenhaehfraca";
     // ZXNzYXNlbmhhZWhmcmFjYQ== (Base64)
     // 6573736173656E686165686672616361 (Hex)
     byte[] clear = clearText.getBytes("UTF-8");
     System.out.println(asHex(clear).toUpperCase());
     SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
     // PKCS5Padding or NoPadding
     Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
     cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
     byte[] encrypted = cipher.doFinal(clear);
     System.out.println(asHex(encrypted).toUpperCase());
}All examples I found generate a key instead of using a static one. Well, I need to use that specific key.
What am I doing wrong? Thank you very much!
Message was edited by:
Magus

\o/
Lame me. I wasn't even going to re-check which was the text and which was the key. I guess I should keep that in mind while dealing with cryptography.
Thanks a lot!!! :D

Similar Messages

  • Using multiple laptops and AirTunes with one static IP

    I just moved into a place that requires a static IP they provided me. After much tinkering, I finally got the Airport Express to work so that I could get online using my Powerbook. However, whenever I'm on the internet (Airport set NOT to distribute IP addresses), I can't use AirTunes. The moment I change that (whether it's using Airport Admin Utility or changing Network Settings on the Powerbook) and I am able to get online again, AirTunes quits and iTunes can't seem to find the remote speakers again.
    I can't even use these both at the same time, and I would eventually like to use AirTunes at the same time as the internet AND be able to connect wirelessly to the internet using my PC laptop. Before moving into the apartment with the static IP, this was possible.
    I keep reading about port mapping - perhaps that is the answer? Problem is, I have no idea what that is. Can somebody please explain why this is happening and offer a solution?

    a) WEP WPA password, ive never set one up for the airport, where do i find out what this password is for my PC?
    You will set up wireless security (WEP or WPA) on the AirPort Express Base Station (AX)..using the AirPort Admin Utility, which is part of AirPort for Windows.
    b) Everytime I run the Airport Express Assistant it gives me an error message saying "Windows is not the current network manager...please change Windows to the default", I dont know why I get this error and I assume windows is the one managing the networks I use.
    Your PC has wireless capability...correct? The AirPort Setup Assistant requires a wireless connection to the AX.
    c) I can connect to the airport through windows, but when in the Airport Management Utility it does not detect the Airport
    Connect your PC directly, using an Ethernet cable, to the Ethernet port of the AX, and then run the AirPort Admin Utility to configure it.
    d) After all this, will Windows and iTunes allow you to stream music thru the Airport Express, like it does on my mac with itunes???
    Yes, you will be able to stream iTunes from your PC to the AX, either wired or wirelessly.

  • ITunes still not syncing correctly with iPhoto 9.4.3

    Since upgrading to version 9.4.x, iTunes hasn't been syncing correctly with iPhoto. There were duplicated events/albums, missing photos, photos not appearing in the same order on iOS devices as they do in iPhoto, etc.
    With each version upgrade since 9.4, this seems to have been improving bit by bit. I have just upgraded to 9.4.3, and now photos appear in the same order as they do in iPhoto. The only problem left for me, is that there are still photos missing in iTunes. Which photos that are missing seems to be completely random.
    I have tried rebuilding the library, which made matters a lot worse. Using 3rd party software like iPhoto library manager to rebuild the library didn't help either (iTunes syncing became a total mess, even more photos were missing afterwards).
    I hope by version 9.4.4, iTunes will read all info correctly from iPhoto again, as it did in version 9.3.2. Anyone else still experience problems?

    Sorry about that. Well, I've tried deleting the AlbumData.xml file as suggested also, but iPhoto itself generates a new file every time it's opened, so that's really a dead end. Rebuilding the library and through iPhoto Library Manager are the steps that required most work, and both did not work either, unfortunately.
    I do believe that I'm not the only experiencing iTunes syncing problem, as there have been many posts here before when 9.4 came out. Like I wrote, it has been better with each upgrade, so there's definitely something in the coding with 9.4.x that messes things up. I had no trouble whatsoever with version 9.3.2 and prior to that.
    Terence Devlin wrote:
    Please share a comprehensive list of things you've already tried so we won't your time - and ours - making suggestions you already know won't work.
    Library size is not part of this issue. 12k photos is not a large library these days, I have one four times that size with no syncing issues.
    Regards
    TD

  • Broadband connection with one static ip

    Hello Everyone!!
    I would like to seek your kind suggestion in mapping static ip address to the local ip address.
    We have a bsnl broadband connection, and bsnl has provided us with one static ip address.
    We are using  broadband modem.
    Now I would liket to map this static ip address to one of the private ip address which is 192.168.1.2(database server).
    i want to do nat above ips if i do so then i dont have no ip to assign to my outside interface.
    I would like to access this device over internet, by typing my public (Static ip ) given by the BSNL.
    Kindly let me know how should i configure this modem.
    security device i have is cisco ASA 5505.
    Need suggestion.
    thanks in advance

    Hi,
    I am afraid that if you are asking for guide to configuring your broadband modem then this is probably not the best section of the Cisco Support Community to do that.
    Generall though it would be best if the modem you have was configured as Bridged device and the public IP address was configured on the ASA5505 directly on its "outside" interface. This saves you from a lot of trouble playing with possible NAT configurations on 2 devices.
    On the ASA5505 you will basicly be configuring Static PAT and NOT Static NAT.
    Static NAT would bind the public IP address to the use of only single internal host.
    Static PAT on the other hand would bind certain TCP/UDP ports to some internal host.
    So naturally we should first determine which ports you need to forward to the internal host and also what the software level of your ASA5505 is so we know which NAT configuration format to use (version number is shown with the command "show version" or in the  main view of the ASDM)
    NAT/ACL 8.2 (and older) Configuration format
    static (inside,outside) tcp interface 80 192.168.1.2 80 netmask 255.255.255.255
    access-list OUTSIDE-IN permit tcp any interface outside eq 80
    access-group OUTSIDE-IN in interface outside
    In the above configuration we first use the "static" command to configure the Static PAT. The configuration basicly states that we want to forward the TCP/80 port using the "outside" "interface" IP address to the local IP address of 192.168.1.2 and local port of TCP/80.
    Finally we make an ACL that allows TCP/80 traffic from anywhere and we attach the ACL to the "outside" interface with "access-group" command. If there is an existing ACL attached to the "outside" interface then you would naturally use that.
    NAT/ACL 8.3 (and newer) Configuration Format
    object network SERVER-WWW
    host 192.168.1.2
    nat (inside,outside) static interface service tcp 80 80
    access-list OUTSIDE-IN permit tcp any object SERVER-WWW eq 80
    access-group OUTSIDE-IN in interface outside
    The above basicly does the same as the first example with the older ASA software. There are just noticiable changes in the NAT and ACL configuration formats.
    Hope this helps
    - Jouni

  • I am having trouble syncing photos with lightroom mobile. Lightroom (on computer) tells me that it's syncing but nothing appears on my I pad. Any comments?

    I am having trouble syncing photos with lightroom mobile. Lightroom (on computer) tells me that it's syncing but nothing appears on my I pad. Any comments?

    however when I try to sync my older ipod with it and upload some new music to it, Itunes keeps telling me that all the previous songs will be erased
    Yes, that's correct. If you don't have the songs that are currently on your iPod also in your new iTunes installation, they will be erased from the iPod if you sync it. Best to start afresh by first transferring all the music on your iPod back to your new computer/iTunes library.
    For iTunes version 7 or later, then you can transfer purchased iTunes store music from the iPod to an authorized computer by using the "file/transfer purchases from iPod" menu. Note that the maximum of 5 authorized computers applies here.
    Find out how to do that here.
    How to copy iTunes purchases from an iPod or iPhone to a computer.
    For all other non purchased content (your own CDs etc), check out the instructions/suggestions here.
    Music from iPod to computer (using option 2). This a manual method using "hidden folders" and although it works, it is a little more involved than other methods.
    Much easier ways are to use one of the many 3rd party programs that copy music from the iPod to the computer.
    One of the most recommended is Yamipod. This is a free program that transfers music from iPod back to the computer. However, it does not transfer playcounts/ratings etc.
    Other free programs are Pod Player, SharePod and Floola.
    If you want to recover just the structure of playlists from the iPod (and not the actual song files themselves), there's iRepo for Windows. which I understand has this feature along with all the standard features for these programs.
    iPodRip also has the feature enabling you to reconstruct playlists.
    There is also CopyTrans. This does preserve ratings/playcounts etc if those are important to you but this program is not free. It also supports video transfer.
    Once all the music is safely back in your new iTunes library, you can sync your iPod as normal.

  • Encrypt pdf with trusted certificates on acrobat pro xi

    Hi all,
    I'm supporting a user who used to encrypt documents with trusted identities (*.fdf) on Acrobat X.
    Now on Acrobat XI, when trying to encrypt a document, he can't used trusted identities. It seems like Acrobat XI only allow encryption from Digital ID (imported from *.pfx)
    Is this correct? Any way we can encrypt on Acrobat XI with trusted identities?
    Thanks.
    Welly

    Hi Welly,
    A digital ID (a P12 or PFX file) consists of three parts; a Public-Key Certificate, the public key, and the private key. The Public-Key Certificate (PKC) is the textual portion that you see in a certificate viewer and contains stuff like the user's name (aka the Subject), the issuers name, validity dates, serial number. etc. The two keys (public and private) have a symbiotic relationship when what one key locks (encrypts) only the corresponding other key can unlock (decrypt). Either key can be used to lock (encrypt) data, but whichever is used the data has to be unlocked (decrypted) using the other key.
    If the file doesn't contain the private key, but just has the PKC and the public key then that is known as a certificate file. Certificate files can be shared with the world, where as a digital ID file is only for use by one person. A certificate file can be view by anyone, but a digital ID file is either password or PIN protected.
    That said, when it comes to encrypting a PDF file using Certificate Security the file is encrypted using one or more certificate files, and only the certificate file is used. However, during the encryption process Acrobat asks the user to select one of their own digital IDs to use in order to keep from locking them out of the file. In reality Acrobat only want access to the public-key portion of the file for the encryption process, but it asks the user to select their digital ID to start. You can elect not to use your own digital ID and skip to the portion where you select the public key certificate of the recipients, and if you know to do so you can select your own, but when it comes time to get back into the file you have to have the private key to decrypt the file and that means you have to have access to the digital ID file. It doesn't make a lot of sense that you would encrypt the file for yourself and not already have the digital ID loaded.
    As far and certificate files go, they can be shared in either the FDF format, the CER file format, or the P7B file format. The format of the file is just the transport mechanism to distribute the public key.
    Steve

  • I have a MacBook Air, OS 10.8.5 I am having trouble sending attachments with Mail. Even small (130K) files don't go. It tries to send then gives up. What can I do to fix this?

    I am having trouble send messages with attachments in Mail. Even small attachments (130K) Mail tries to send, then gives up and the message sits in my out box. How can I fix this?

    1. You need an external DVD drive.
    2. There are no Mac OS X applications or other software in the iTunes App Store.
    (116312)

  • I am being repetedly asked to verify certificates and also cannot use xmarks as it does not appear to work correctly with my current version of firefox (8.0) and my mac 10.6.8. I tried removing and reinstalling but unsuccesfully.

    whenever i start firefox i receive a message saying that the certificate is not recognised - it is a certificate relating to xmarks.
    in fact upon installation i received another message stating that it wouldnt work correctly with my version of firefox. now i have updated firefox but receive the same message.
    thinking that it was an issue relating to certificates i went into "preferences" and removed all the certificates in the "authorities" section also given that i didnt recongnise any of them (e.g. turktrust!!).

    Hi,
    /Users/sarahschadek/Desktop/Safari.app/Contents/MacOS/Safari
    Move the Safari app from the Desktop to the Applications folder.
    Restart your Mac.
    That's why you see this:
    When I try to do the updates my computer says it has ready it goes through like it is downloading them then at the end it says some of the files could not be saved to "/" files.
    After your restart your Mac, click the Apple  menu (top left in your screen) then click:  Software Update ...
    Carolyn  

  • Unable to open encrypted pages with 11.0.02 on Win7 IE10 system fully updated.

    Just get blank screen with "X" in upper left. Have searched this forum and tried all suggestions including:
    Cleared and reset all IE10 settings - no luck
    Disabled and enabled Adobe add-ins - no luck
    Right click on link and 'save as' or 'open' and others on the Tool menu - no luck
    System restore - no luck
    Disabled and enabled other add-ins - no luck
    My win8 IE10 system opens encrypted pages with no problem. I set the IE10 tab options identically in the win7 system - no luck
    Contacted websites using encryption (bank and credit cards). They have no other suggestions.
    Any other suggestions?

    Hi there,
    Welcome to Adobe Forums.
    Try turning off the Protected View under Edit > Preferences >Security (Enhanced) in Adobe Reader.
    Hope this helps!
    Thanks!

  • Can anyone recommend a portable USB 3.0 drive with hardware encryption, compatible with OSX and Windows 7.  I need it for my MacBook Pro 13", 2012, running Mountain Lion

    Can anyone recommend a portable USB 3.0 drive with hardware encryption, compatible with OSX Mountain Lion and Windows 7.  I need it for my MacBook Pro 13”, 2012, running Mountain Lion & Windows 7 Ultimate - BootCamp.  I’ve heard that the Buffalo MiniStation Encryption does not work with OSX, is that true..?  I'd like it to work with both operating systems, using the built in hardware encryption.  Thanks

    This article may help: A flashing question mark appears when you start your Mac.

  • Print profiles no longer working correctly with CS6 64bit to my Epson R2880

    Hi, until recently, my print profiles were working correctly  with CS6 64bit (Win 7 ultimate 64) to my Epson R2880, they now print washed out/desaturated  but the same profiles still print correctly using Lightroom 4. has there  been an update that could have affected things or are there any other  suggestion? Thanks, Dave.

    Hi,
    I hope someone can help!
    I recently bought my first Mac, a great MacBook Pro which I love!
    I use Lightroom3 and Photoshop CS5 to edit photos and now want to print from my Epson R1800.
    I found that the prints initially came off very dark & contrasty, so I calibrated both the MBP screen and my Samsung SuncMaster 245B monitor with my Spyder2 and the Colorvision software.
    Even after establishing colour profiles for both screens, the printed image was still far darker and "heavier" than that shown on screen. This was the same whether printing from LR3 or from the Mac Preview app (it was worth trying I thought!).
    So searching for help on the web I came across this thread and now wonder whether I should uninstall my driver (6.57) and reinstall the printer with 6.23.
    Stephen did you find that this worked - did PS CS5 behave after that?
    Of course I'm trying to print some work soon and in desperation could adjust every (edited) image by brightening & reducing contrast, however with dozens to print it seems crazy to do that, not to mention wrong!
    Thanks for any help!
    Paul

  • McAfee SiteAdvisor is no longer working with my Safari 8.0.  I never had trouble using it with Safari before this latest version.  Has anyone else had this problem?

    McAfee SiteAdvisor is no longer working with my Safari 8.0.  I never had trouble using it with Safari before this latest version.  Has anyone else had this problem?  I contacted McAfee support and they said nobody else is reporting this issue.

    Wow, life is certainly tough for you.
    S***t happens.  That's why there's a warranty.

  • Problem in aligning dynamic UI with the static UI

    Hi All,
    I have problem in aligning dynamic UI with the static UI, I am using Matrix layout.
    Static fields are spread over 2 colums and 3 rows:
    lableA SPACE input field SPACESPACE lable B SPACE input field
    lableC SPACE dropdown SPACESPACElableD SPACE dropdown
    lableE SPACE dropdown SPACESPACElableF SPACE dropdown
    Now when a value is selected in C, than E becomes visible, and depending on the values selected in E, there are dynamic UI generated, i.e dynamic lables and depending on some validation it will be either a dropdowns or input fiels or both.
    at run time screen is like this:
    lableA SPACE input field SPACESPACE lable B SPACE input field
    lableC SPACE dropdown SPACESPACElableD SPACE dropdown
    lableE SPACE dropdown SPACESPACElableF SPACE dropdown
    dynaSPACEdropdown
    dynbSPACEinput field
    if I change my selection in E than layout looks like:
    lableA SPACE input field SPACESPACE lable B SPACE input field
    lableC SPACE dropdown SPACESPACElableD SPACE dropdown
    lableE SPACE dropdown SPACESPACElableF SPACE dropdown
    dynaSPACESPACEdropdown
    dynbSPACESPACEinput field
    Requirment: I need all the lables as well as dropdown/ input fiels in line with the static fields irrespective of my selection in E.
    Something like this:
    lableA SPACE input field SPACESPACE lable B SPACE input field
    lableC SPACE dropdown SPACESPACElableD SPACE dropdown
    lableE SPACE dropdown SPACESPACElableF SPACE dropdown
    dyna   SPACEdropdown
    dynbSPACESinput field
    dyncSPACESdropdown
    All this elements are in a group and that group has 2 transparent containers, 1 for static and for holding dynamic UI.
    I tried playing with the container properties, and also tried fixing width of dynamic UI but still the alignment issue is encountered.
    Can U guys plz give in ur valuable inputs as i need to fix this urgently.
    Regards,
    JJ

    Hi Armin,
    Can you please elaborate your solution ?, I do not have an idea of InvisibleElement & IWDView.resetView() ,
    If you can give me the exact pointer than it would be great and a good learning exp. for me.
    Thanks for the action assignment part, it worked.
    if (wdContext.nodeMaterialClass().size() > 0 && wdContext.currentContextElement().getActionMatCls()) {
         if (wdContext.currentMaterialClassElement().getMaterialClass_Description() != null || !wdContext.currentMaterialClassElement ().getMaterialClass_Description().equalsIgnoreCase(" ")) {
               IWDGroup Searchgroup = (IWDGroup) view.getElement("DynGroup");
    Searchgroup.destroyAllChildren();
    view.getContext().reset(false);
                                                      for (int i = 0; i < wdContext.nodeMaterialCharateristcs().size(); i++) {
                                  //this for label
         IWDLabel CharLabel = (IWDLabel) view.createElement(IWDLabel.class, "label" + i);
         CharLabel.setText(wdContext.nodeMaterialCharateristcs().getMaterialCharateristcsElementAt(i).getDescr_Char());
         CharLabel.setDesign(WDLabelDesign.EMPHASIZED);
         CharLabel.createLayoutData(MatrixHeadData.class);                              CharLabel.setWidth("154px");                              Searchgroup.addChild(CharLabel);
                 further there are conditions to create either dropdown or input field
    Can you please point where and how to apply your solution.
    Regards,
    JJ

  • Access of undefined method/property through reference with a static type Class

    I get the following error: (it's not word for word but you get the idea)
    Error: Access of undefined method getStatus through reference with a static type Class.
    Here's what's happening in the code. I'm trying to create a User class that is instantiated at the start of my app. I want the User class to have properties like mainStatus, with helper methods like setStatus etc. Pretty simple.
    so on my HardDisk I have my flash_working folder with all my flash projects. I created my class file/package under the directory com.mypackage
    package com.mypackage
        import flash.display.*;
        public class User extends Sprite
            public var mainStatus:int;
            public function User()
                trace("User Created!");
                mainStatus = 0;
            public function setStatus(status:int):void
             mainStatus = status;
        public function getStatus():int
            return mainStatus;
    Ok, so far so good.
    now I created a new .fla file under the root of /flash_working/. The class file is in /com/mypackage/User.as
    in my .fla file I have:
    import com.mypackage.User;
    var myUser:User = new User();
    var i = User.getStatus();
    trace(i);
    That's all the code I have. Could someone please explain why it's giving me that error?
    If I try to access the public var mainStatus through user.mainStatus that gives a similar error saying:
    Error: Access of undefined property mainStatus through reference with a static type Class.
    Thanks for any help!
    jef3189

    the public getStatus() function that you created needs to be referred to through an instance of the class.
    So:
    import com.mypackage.User;
    var myUser:User = new User();
    var i = myUser.getStatus();
    trace(i);
    Also, an aside. You can create a getter/setter for status, to avoid having to do the function as such.
    package com.mypackage
        import flash.display.*;
        public class User extends Sprite
            public var mainStatus:int;
            public function get status():int
                return mainStatus;
            public function set status(value:int):void
                 mainStatus = value as int;
              public function User()
                trace("User Created!");
                mainStatus = 0;
    And then, you can call it as:
    import com.mypackage.User;
    var myUser:User = new User();
    trace(myUser.status);
    EDIT
    I just noticed that you made the variable public as well, which means you can access it without getter/setter or function.
    import com.mypackage.User;
    var myUser:User = new User();
    trace(myUser.mainStatus);

  • LR 2.1 & 2.0 ~ DRAG & DROP not working correctly with  photos when moving, applying keywords

    Today this issue started, originally in 2.0, updated to 2.1 and issue continues.
    Issue: DRAG & DROP feature with mouse (or pad on laptop) will select multiple photos, (with CTRL & SHIFT key as typical with Windows machines)but when I try to move them to a different folder, or drop them onto a keyword, it will not work.
    Specifically, I select two photos to move to a different folder, the selection work, but when I try to "grab" the selected photos, Lightroom defaults to One Photo, and it will not grab it to move it. However, I can "right click" on the intended folder and can select "move selected photos to folder" and that works. This issue also applys to assigning keywords, and I would assume other similiar actions. I should note, that I can "rotate", assign "labels", "stars", and Keywords from Keyword sets, it just happens with the "Drag & Drop" feature.
    Help
    The feature works correctly in other Windows programs, so I'm sure it's related to Lightroom and not the mouse.
    I have a Windows Vista machine, 3GB RAM 160GB HD, ~ 75% free space, AMD Turion X2 Dual Core 70 Processor. Everything has worked fine up until this morning.
    Prior to upgrading to 2.1, I optimized my Catalogue. Everything seems to work fine except this feature.
    Help

    Drag by the actual image area of the thumbnail, not the surrounding 'fake slide' cell.
    That's a feature of Lightroom's grid view. Clicking on image area of thumbnail keeps the multiple selection and makes the image clicked the primary select. Clicking on the outer thumbnail area deselects all but the active image.

Maybe you are looking for