Urgent help!  does anyone has sample code to do encry in c & decry in java

Does anyone has a very simple code to encrypt a string in c (openssl for example) and then decrypt the same string in java?
it should be very simple but i just can get the ball rolling. i always get different data (even in hex string representation) using the same key and plain text (all in hex) to even just do encryption (not even decryption yet). To my understanding, DES is just bits manipulation. So the output bit pattern should be the same regardless C or Java, right?
for example, in openssl, when i do ecb:
the key:
0123456789ABCDEF
the plain text:
0101010101010101
the in:
0101010101010101
the out:
B4FD231647A5BEC0
but doing the same in java i got
3A2EAD12F475D82C as the encryption output
It is very strange.
Hope someone could help me.
Thanks
-- Jin

whew! i finally get the base64 working. Here is my data from openssl run using DES with ECB mode and no padding: (the des_ecb_encrypt function is des/ecb/nopadding, right?)
thanks alot
-- jin
0123456789ABCDEF
the key in base64 encoding is:ASNFZ4mrze8=
the plaintext in hex:
0101010101010101
the plaintext in base64 encoding is:AQEBAQEBAQE=
the encrypted output in hex:
B4FD231647A5BEC0
the encrypted output in base64 encoding is:tP0jFkelvsA=
the decrypted text in hex:
0101010101010101
the decrypted text in base64 encoding is:AQEBAQEBAQE=
here is the code. see if you see the same thing. it works fine alone but just not the same result i use the SUN JCE ... that is the frustration part.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <ctype.h>
#include <openssl/des.h>
#define Assert(Cond) if (!(Cond)) abort()
static const char Base64[] =
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char Pad64 = '=';
int main(int argc, char *argv[])
        int i;
        des_cblock in,out,outin;
        unsigned char base64EncodedText[255];
        unsigned char temp[255];
        size_t targsize;
        size_t srclength;
        des_key_schedule keySchedule;
        unsigned char plainText[8] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};
        unsigned char key[8] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
        // now create the key schedule
        if(DES_set_key(&key, &keySchedule) != 0) {
          // something is wrong, unable to create key schedule
          printf("Unable to create the key schedule.");
          return 1;
        // now the key schedule is created, encrypte the data
        // in block contains the plain text, the out block contains the encrypted cyphertext,
        // and outin contains the decrypted plain text (should be the same value as in)
        memcpy(in,plainText,8);
        memset(out,0,8);
        memset(outin,0,8);
        // ecb mode is the simplest mode, takes in only 8 bytes (a cblock) and output a cblock
        des_ecb_encrypt(&in, &out, keySchedule, DES_ENCRYPT);
        des_ecb_encrypt(&out, &outin, keySchedule, DES_DECRYPT);
        printf("\nthe key in hex:\n");
  for(i = 0; i < 8; i++) {
    printf("%02X", key);
printf("\nthe key in base64 encoding is:");
memcpy(temp, key, 8);
temp[8] ='\0';
targsize = base64encode(temp, 8, base64EncodedText, targsize);
printf("%s", base64EncodedText);
printf("\nthe plaintext in hex:\n");
for(i = 0; i < 8; i++) {
printf("%02X", in[i]);
printf("\nthe plaintext in base64 encoding is:");
memcpy(temp, in, 8);
temp[8] ='\0';
targsize = base64encode(temp, 8, base64EncodedText, targsize);
printf("%s", base64EncodedText);
printf("targsize is %d", targsize);
printf("\nthe encrypted output in hex:\n");
for(i=0; i<8; i++) {
printf("%02X", out[i]);
printf("\nthe encrypted output in base64 encoding is:");
memcpy(temp, out, 8);
temp[8] ='\0';
targsize = base64encode(temp, 8, base64EncodedText, targsize);
printf("%s", base64EncodedText);
printf("\nthe decrypted text in hex:\n");
for(i = 0; i < 8; i++) {
printf("%02X", outin[i]);
printf("\nthe decrypted text in base64 encoding is:");
memcpy(temp, outin, 8);
temp[8] ='\0';
targsize= base64encode(temp, 8, base64EncodedText, targsize);
printf("%s", base64EncodedText);
printf("\n");
return 1;
int base64encode(unsigned char *src, size_t srclength,
char *target, size_t targsize)
size_t datalength = 0;
unsigned char input[3];
unsigned char output[4];
size_t i;
while (2 < srclength) {
input[0] = *src++;
input[1] = *src++;
input[2] = *src++;
srclength -= 3;
output[0] = input[0] >> 2;
output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
output[3] = input[2] & 0x3f;
Assert(output[0] < 64);
Assert(output[1] < 64);
Assert(output[2] < 64);
Assert(output[3] < 64);
if (datalength + 4 > targsize)
return (-1);
target[datalength++] = Base64[output[0]];
target[datalength++] = Base64[output[1]];
target[datalength++] = Base64[output[2]];
target[datalength++] = Base64[output[3]];
/* Now we worry about padding. */
if (0 != srclength) {
/* Get what's left. */
input[0] = input[1] = input[2] = '\0';
for (i = 0; i < srclength; i++)
input[i] = *src++;
output[0] = input[0] >> 2;
output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
Assert(output[0] < 64);
Assert(output[1] < 64);
Assert(output[2] < 64);
if (datalength + 4 > targsize)
return (-1);
target[datalength++] = Base64[output[0]];
target[datalength++] = Base64[output[1]];
if (srclength == 1)
target[datalength++] = Pad64;
else
target[datalength++] = Base64[output[2]];
target[datalength++] = Pad64;
if (datalength >= targsize)
return (-1);
target[datalength] = '\0'; /* Returned value doesn't count \0. */
return (datalength);
[code                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Does anyone has a problem with the screen of the new ipad? (there's a part of the screen which the color in it is "very" bright) and when I move the aluminium part of the smart cover when it's attached to the ipad the colors change!! Help!!!

    Does anyone has a problem with the screen of the new ipad? (there's a part of the screen which the color in it is "very" bright) and when I move the aluminium part of the smart cover when it's attached to the ipad the colors change!! Help!!!

    I'd take it into my local APple store and have them look at it. There may be something wrong inside your device.

  • I want to write a java program that can add a user to a role or sub role to the Profile Database in iPlanet Portal Server 3.0. Does anyone has any idea or a sample program do such thing. Thanks, Tommy

    I want to write a java program that can add a user to a role or sub role to the Profile Database in iPlanet Portal Server 3.0. Does anyone has any idea or a sample program do such thing? Thanks, Tommy

    // create the user profile, get the handle back,
    // and set the membership profile attributes.
    ProfileAdmin newProfile = null;
    try {
    // the users profile name is the domain      
    // he belongs to plus their userName
    // you will request.domain if your doing this from a servlet, domain_name is the domain_name the user belongs too
    String profileName = domain_name + "/" + user;
         if (debug.messageEnabled()) {
    debug.message("creating profile for " + profileName);
    // create the user profile object
    newProfile = ProfileManager.createProfile(
    getSession(), profileName ,Profile.USER);
    UserProfile userProfile = (UserProfile)newProfile;
         // set the role the user is a member of. Default is to set
         // the users to the default role of the domain they surfed to
         StringBuffer roleName = new StringBuffer(64);
    // request.domain instead of domain_name if your doing this from a servlet ..
    Profile dp = getDomainProfile(domain_name);
    roleName.append(dp.getAttributeString("iwtAuth-defaultRole"));
         if (debug.messageEnabled()) {
    debug.message("setting role for " + user + " = " + roleName);
    userProfile.setRole(roleName.toString());
    newProfile.store(false);
    } catch (ProfileException pe) {
         debug.error("profile exception occured: ",pe);
    return;
    } catch (ProfileException pe) {
         debug.error("login exception occured: ",le);
    return;
    HTH ..

  • Any one has sample code of Multi-Thread Embbeded SQL in C ?

    We want to write multh-thread code using Embbeded SQL in C.
    The Open Client version is 15.7 SP100.
    The Sybase Document : "Embedded SQL/C Programmers Guide (Open Client) " said it supports Multiple SQLCAs,
    but has no sample code about this.
    Any one has sample code of Multi-Thread Embbeded SQL in C ?
    Thanks!

    Hi,
    I am asking around and will see if anyone has anything. Please note this though:
    http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc00371.1570/html/sdkrblnx/sdkrblnx39.htm
    Thanks,
    Dawn Kim

  • I have a canon mf5940dn, it is connected via USB to my macbook air, and yet, when i want to print smith, it says the printer is not connected. does anyone has any idea why? is there a guide to do it properly?

    I have a canon printer mf5940dn, it is connected via USB to my macbook air, and yet, when I want to print smth, it says the printer is not connected. does anyone has any idea why? is there a guide to do it properly?

    Hi,
    I am currently replying to this as it shows in the iChat Community.
    I have asked the Hosts to move it to Snow Leopard  (you should not lose contact with it through any email links you get)
    I also don't do Wirelss printing so I can't actaully help either.
    10:01 PM      Friday; July 29, 2011
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb( 10.6.8)
     Mac OS X (10.6.8),
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • Does anyone have the code to use an image button as the reset button?

    Does anyone have the code to use an image button as the reset button? I'm finally at the end of the form and got the submit button to work as an image button, but cannot do the same with the reset button.  Any help is greatly appreciated!

    I agree. 
    http://www.456bereastreet.com/archive/200909/almost_never_add_a_reset_button_to_a_form/
    Nancy O.

  • Does anyone has problem with the Glossary tab in RB8?

    The glossary tab does'nt show on *CHM file. Does anyone has that problem?
    1) Install RH8 on XP SP2 and register hhactivex.dll
    2) Start RH8
    3) Create new project.
    4) Click on '+' sign of Glossary from Project Manager to expand it and double click the Glossary(Default) to show the GLossary Pod.
    5) Type 'First' in the Term input field on the Glossary Pod, and click the + button to add it.
    6) Go to the 'Definition for :first section of the Pod and type in 'First'
    7) Save and generate the CHM file
    This is the first time I create a new project in RH8 with Glossary.
    If I import a previous project created with RoboHelp for Office X4 which has Glossary, and convert project to RH8 format and generate the CHM file, then the CHM file has the Glossary tab.
    I can't possibly beleive it is a bug in RH8 . However, what mistake did I make?
    This happens on XP SP2, RH 8.0.0.0.203, on XP SP3 with RH 8.0.2.208, on Win7 with RH 8.0.2.208. Basically, it doesn't matter on what PC we install RH8, doesn't matter how many time you register hhactivex.dll, the glossary tab never shows up. Howver, it shoes up on Winhelp.
    Thanks

    Hi there
    No, I don't believe they are ameteurs. Besides, some ameteurs do better work than "professionals".
    To be fair, some bugs are elusive. We may see them and report them but when the development team examines things they repeatedly and stubbornly fail to reveal themselves.
    Cheers... Rick
    Helpful and Handy Links
    RoboHelp Wish Form/Bug Reporting Form
    Begin learning RoboHelp HTML 7 or 8 within the day - $24.95!
    Adobe Certified RoboHelp HTML Training
    SorcerStone Blog
    RoboHelp eBooks

  • After upgrading to Yosemite and Aperture 3.6 all the library icons are shown plain. Does anyone has a hint?

    After upgrading to Yosemite and Aperture 3.6 all the library icons are shown plain. Does anyone has a hint?

    If it is still slow after removing Symantec, you may need a RAM upgrade. Yosemite can run very poorly on older machines with only 4 GB RAM.

  • Hello, I just got an iPhone 4S and it seems that the bluetooth function in it doesn't work. I tried few times to pair it to other non Apple phones and it never worked. Does anyone has an idea how to solve the problem? Tks.

    Hello, I just got an iPhone 4S and it seems that the bluetooth function in it doesn't work. I tried few times to pair it to other non Apple phones but it never worked. Does anyone has an idea how to solve the problem? Tks.

    This is not a feature of iPhone, iPad or iOS.
    Bluetooth is supported for stereo headsets/speakers, handsfree telephone
    devices/headsets, some keyboards, some peer-to-peer apps from the
    app store and internet tethering where provided by the carrier.
    Other than this it will not connect to a phone/computer/device.  (thanks to ckuan for the wording)

  • After updating iphone 4s to 6.1 version my battery percentage stood at 1 percent. Does anyone has same problem? Or its update bug?

    After updating iphone 4s to 6.1 version my battery percentage stood at 1 percent. Does anyone has same problem? Or its update bug?

    THIS is "quite a few": https://discussions.apple.com/thread/3391947
    As are these:
    https://discussions.apple.com/thread/3391947?tstart=0
    https://discussions.apple.com/thread/3484755?tstart=0
    https://discussions.apple.com/thread/3481668?tstart=0
    https://discussions.apple.com/thread/3518760?tstart=0
    https://discussions.apple.com/thread/2755090?tstart=0
    https://discussions.apple.com/thread/3507356?tstart=30
    https://discussions.apple.com/thread/3482083?tstart=60
    https://discussions.apple.com/thread/3492588?tstart=60
    https://discussions.apple.com/thread/3397244?tstart=90
    And older ones:
    Battery Meter/Life Problems with 4.0.2
    4.0.2 guzzling my battery. Your's too?
    4.0.1 battery life
    Battery runs out very quicky in iOS 4.0.1
    Battery nearly nonexistant after 4.0 upgrade
    Dead battery after few hours on standby using 4.0 software
    3.1.3 battery problem
    OS 3.1.3 battery issues
    3.1.3 upgrade - shortened battery life?
    Battery life cut after 3.1.3 update on iPhone 3G
    3.1.3 Firmware is a battery killer - how do I back out this upgrade?
    Poor battery life with iPhone 3G running 3.1.2
    3.1.2 EXTREME battery drain - what gives?
    3.1 Battery nightmare
    iPhone 3GS with fw 3.1 – battery life gets even worse
    Battery Issues with 3.0.1
    BATTERY drain with 3.0
    upgrade to 3.0 drains my battery
    Battery Drain after Update 2.2.1
    Battery Life Radically Decreased after 2.2.1 Firmware Update
    As you can see, battery issues have been common since the first iphone, frequently reported after an upgrade, but not always. So to blame a specific version doesn't describe the problem sufficiently to find a resolution.

  • Does anyone has the same scrolling problem? My macbook air 13''(2010) running lion, when files in a folder arranged by kind, every scrolling paused for a second..?

    does anyone has the same scrolling problem? My macbook air 13''(2010) running lion, when files in a folder arranged by kind, every scrolling paused for a second..?

    does anyone has the same scrolling problem? My macbook air 13''(2010) running lion, when files in a folder arranged by kind, every scrolling paused for a second..?

  • Does anyone know what code 43 is?

    does anyone know what code 43 means ipod isn't being recognized by computer or docking station and wont charge only in sleep mode?

    Check for hardware issues
    Try to restore your iOS device two more times while connected with a cable, computer, and network you know are good. Also, confirm your security software and settings are allowing communication between your device and update servers. If you still see the alert when you update or restore, contact Apple support.
    Common errors: 1, 10-47, 1002, 1011, 1012, 1014, 1000-1020.
    - If still not successful that usually indicates a hardware problem and an appointment at the Genius Bar of an Apple store is in order.
      Apple Retail Store - Genius Bar

  • Can somebody help in getting a sample code to upload a csv file

    Can somebody help in getting a sample code to upload csv file from folder every 30 minutes that will update a particular record in crm ondemand

    Hi,
    I'm sorry but I do not have a code sample which performs the scenario you have described below. The samples I did provide are meant to illustrate the use of CRM On Demand Web Services and can be used as a guide to those developing integrations.
    If you have specific questions or issues that arise during the development of your integration please don't hesitate to post them, however, I would recommend that you contact Oracle Consulting Services or one of the many system integrators who actively develop applications which integrate with CRMOD if you require more in-depth assistance.
    Thanks,
    Sean

  • Cannot create new folders on desktop. Cannot drag new items onto desktop. Desktop in Finder opens with Terminal. Not sure if this has anything to do with upgrading to Mavericks but I need help if anyone has ideas. Thank you.

    I can no longer create new folders on my desktop. The option to do that is now light gray on the drop down menu and can't be selected.
    I cannot drag new items onto desktop any longer either.
    The Desktop in Finder opens with Terminal.
    Folders and items on Desktop open and work normally.
    Not sure if this has anything to do with upgrading to Mavericks but I need help if anyone has ideas.
    Thank you.

    Take these steps if the cursor changes from an arrow to a white "prohibited" symbol when you try to move an icon on the Desktop.
    Sometimes the problem may be solved just by logging out or rebooting. Try that first, if you haven't already done it. Otherwise, continue.
    Select the icon of your home folder (a house) in the sidebar of a Finder window and open it. The Desktop folder is one of the subfolders. Select it and open the Info window. In the General section of the window, the Kind will be either Folder  or something else, such as Anything.
    If the Kind is Folder, uncheck the box marked Locked. Close the Info window and test.
    If the Kind is not Folder, make sure the Locked box is not checked and that you have Read & Write privileges in the  Sharing & Permissions section. Then close the Info window and do as follows.
    Back up all data.
    Triple-click anywhere in the line below on this page to select it:
    xattr -d com.apple.FinderInfo Desktop
    Copy the selected text to the Clipboard by pressing the key combination command-C.
    Launch the Terminal application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Terminal in the icon grid.
    Paste into the Terminal window (command-V). You should get a new line ending in a dollar sign (“$”). Quit Terminal.
    Relaunch the Finder.
    If the problem is now resolved, and if you use iPhoto, continue.
    Quit iPhoto if it's running. Launch it while holding down the option key. It will prompt you to select a library. Choose the one you want to use (not the Desktop folder.)

  • Help, does there has any sdk or something about itunes on mac??

    help, does there has any sdk or something about itunes on mac??
    i want develop a app to read information from itunes and change some content in it.
    thanks for any help;)

    If you are talking about an iTunes API in which you could make an app similar to a Twitter client for Twitter, there is no such thing. If you are talking about the iPhone SDK to make an App which appears in the iTunes store, you can download Xcode in the Mac App Store or at http://developer.apple.com/devcenter/ios/index.action

Maybe you are looking for