3DES - Php crypto codes 2 Java codes convertion problem

I give all php and java codes I convert one by one but I didnt get same result where is my mistake and what shall I do. Thanks for all.
Php Code
$key = "db9ca45ee012dcabaff193ca";
$input = sha1("MehmetKaraman");
$td = mcrypt_module_open('tripledes', '', 'ecb', '');
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
mcrypt_generic_init($td, $key, $iv);
$encrypted_data = mcrypt_generic($td, $input);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
echo sha1(bin2hex($encrypted_data));
Output : d7eaa53ab43683a1323cfae877a24efb4a918411
Java Code :
String message= “MehmetKaraman”;
byte[] input = MessageDigest.getInstance("SHA1").digest(message.getBytes("utf-8"));
     final Cipher cipher = Cipher.getInstance("DESede/ECB/NoPadding");
     final SecretKey key = new SecretKeySpec("db9ca45ee012dcabaff193ca".getBytes("utf-8"), "DESede");
cipher.init(Cipher.ENCRYPT_MODE, key );
if( input.length % 8 != 0){
     byte [] in2 = new byte[input.length+ 8- input.length%8];
     for(int i = 0;i<input.length;i++){
     in2=input[i];
     input = in2;
     final byte[] encrypted_data = cipher.doFinal(input);
     System.out.println(bin2hex(MessageDigest.getInstance("SHA1").digest(bin2hex(encrypted_data).getBytes())));
Output : 626b61642ec4ba8f7467933832619d492a6fdde1

Either you need$input = sha1("MehmetKaraman", true);or in your Java you need to hex encode your sha1 digest before encrypting. When I do either of these and emulate your Java bin2hex() method I get a match.
I don't understand why people seem unable to do simple debugging. If you had read the PHP documentation for the sha1() function and had printed out the results at each stage it would have been obvious.
P.S. The zero padding implemented by your codeif( input.length % 8 != 0){
byte [] in2 = new byte[input.length+ 8- input.length%8];
for(int i = 0;i<input.length;i++){
in2=input[i];
input = in2;
}can be replaced by 1 line using one of the methods in class java.util.Arrays.
Edited by: sabre150 on Sep 15, 2010 3:10 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • SVG to JavaFX code Converter for Designer-Developer-Workflow

    I created an SVG to JavaFX code Converter while working on a project. Although its still a work in progress, it has been so useful for me ever since. Its available at convfx.codebase101.com for anyone that is interested in the Designer-Developer workflow (similar to JavaFX 1.x, which was the inspiration). [url http://www.codebase101.com/convfx/dist/convfx_dl.php]Download
    Hope someone finds it useful.
    Edited by: Burabari55 on Mar 22, 2012 6:41 PM, added download link.

    That is very nice Burabari, thanks for sharing it.

  • PHP exception code in FaultEvent?

    Hi-
    The PHP exception code doesn't seem to get mapped into a
    FaultEvent...only the exception *message* seems to be available in
    a FaultEvent. I was hoping to use an exception code in a FaultEvent
    to drive logic in Flex (i.e if code == 100, then x, if code == 200,
    then y, etc).
    Am I correct in assuming that the PHP exception code does not
    get mapped into a FaultEvent? If so, how are other people using
    FaultEvents to drive logic decisions in Flex?
    One idea I had was to use a serialized object as the PHP
    exception message, and unserialize the resulting
    FaultEvent->faultDetail message in Flex. This method works OK,
    but I was hoping for a more elegant solution.
    Thanks!
    Greg

    Adobe Newsbot hopes that the following resources helps you.
    NewsBot is experimental and any feedback (reply to this post) on
    its utility will be appreciated:
    Flex 3 - About data access:
    Flex data access components are based on a service-oriented
    architecture .... objects, such as ColdFusion components (CFCs),
    Java objects, PHP objects,
    Link:
    http://livedocs.adobe.com/flex/3/html/data_intro_2.html
    AMF3 PHP Server Objects to Flex Client Object Relational
    Mapping:
    Apr 16, 2008 ... fig1.png Flex Based Rich Internet
    Applications (RIAs) by definition typically require server access
    to provide the information resources and
    Link:
    http://www.insideria.com/2008/04/amf3-php-server-objects-to-fle.html
    Flex 3 - Using HTTPService components:
    You can use a Flex HTTPService component in conjunction with
    PHP and a SQL ... The resultFormat property of the HTTPService
    component is set to object
    Link:
    http://livedocs.adobe.com/flex/3/html/data_access_2.html
    Adobe - Developer Center : Using Flex 2 RemoteObject and
    SabreAMF:
    After SabreAMF maps the PHP objects in the return array to
    com.renaun.samples.vo.UserVO , the application on the Flex side
    deserializes this return array
    Link:
    http://www.adobe.com/devnet/flex/articles/remoteobject_sabreamf_05.html
    Flex 3 - About working with data in Flex Builder:
    Flex Builder provides a set of data wizards that
    automatically generate database applications that use PHP, J2EE, or
    ASP.NET.
    Link:
    http://livedocs.adobe.com/flex/3/html/data_2.html
    Disclaimer: This response is generated automatically by the
    Adobe NewsBot based on Adobe
    Community
    Engine.

  • ARB PHP Sample Code SOAP Exception

    Hello Everybody
    I m using ARB PHP Sample Code.
    I m using it as it is provided with my login id and transaction key
    I m using PHP 5.2 version
    I m quite new to SOAP.
    Everything seems fine but the script is throwing following exception.
    SoapFault exception: [soap:Client] Server was unable to read request.
    ---> There is an error in XML document (2, 584). ---> Input string was
    not in a correct format. in /mysite//php_arb/PHP/
    api_authorize_net_soap_v1.php:1869 Stack trace: #0 /mysite//php_arb/
    PHP/api_authorize_net_soap_v1.php(1869): SoapClient-
    >__soapCall('ARBCreateSubscr...', Array) #1 /mysite//php_arb/PHP/
    subscription_create.php(24): AuthorizeNetWS-
    >ARBCreateSubscription(Object(ARBCreateSubscription)) #2
    May i please have some help on how to resolve this and get the code
    working for me?
    I m trying to trace out the issue but my efforts are in vain.
    I look forward to recieve some help from everybody in this group
    Pls reply
    Thanking You in advance

    Hello Devster,
    Thank you to post your question on TechNet forum.
    After reviewing the whole post, I have a question to you. You can access the report via the link, http://myServer/Reports_DEVPROJECT/Pages/Report.aspx?ItemPath=%2fData+Mgmt%2fSample+Letter.
    From the URL, I can see that the report is located at: /Data Mgmt/Sample Letter, instead of /DataMgmt/Sample Letter. In addition, I found that the target report is "/DataMgmt/Sample HAP Letter" instead of "/DataMgmt/Sample Letter" as the error described. I
    am not sure whether you post out the correct code segment.
    Please check the above things on your side, and hope it is helpful to you.
    Regards,
    Edward
    Edward Zhu
    TechNet Community Support

  • Where's the best place to get code converted between ActionScript 2.0 and 3.0?

    Where's the best place to get code converted between ActionScript 2.0 and 3.0?
    If I just have occasional (very small) projects, what's the best way to get them done really fast by somebody who knows both 2.0 and 3.0?
    Thanks, Dan

    You have pretty much answered your own question... hire someone who has fairly thorough knowledge of both AS2 and AS3.
    I have heard there are some tools for converting between AS2 and AS3, but I have no knowledge of them other than having heard that they cannot convert all things.... which makes sense because there is not always a one-to-one relationship to how things ae done with AS2 and how they get done with AS3.

  • PHP require_once code is not working any more

    Before updating to Dreamweaver CC14 (from CS5.5), my php "require_once" files were working fine. When I imported the "ste" file into CC2014, and upload the files as usual, I get this error:
    Warning: require_once(/var/chroot/home/content/d/m/w/dmwebcreation/html/includes/_footer.php) [function.require-once]: failed to open stream: No such file or directory in /home/content/d/m/w/dmwebcreation/html/dmweb-2/index.php on line 15
    Fatal error: require_once() [function.require]: Failed opening required '/var/chroot/home/content/d/m/w/dmwebcreation/html/includes/_footer.php' (include_path='.:/usr/local/php5_3/lib/php') in /home/content/d/m/w/dmwebcreation/html/dmweb-2/index.php on line 15
    This is the php code that I am using in order to have these files added to any page and any directory.
    <?php
       $path = $_SERVER['DOCUMENT_ROOT'];
       $path .= "/includes/_footer.php";
       require_once($path);
    ?>
    This is the location for my test file:    http://dm-webcreation.com/dmweb-2/index.php
    I have Dreamweaver CC 2014 set up as "Links Relative to SITE ROOT" ... so that these files brought in from any files in any direction.
    Has something changed in CC 2014?

    I am using "Links Relative to Site Root" because of my "includes" files which I need to have relative to the site root so that it will not matter where I place the main files, I can still use the "includes" files as "templates" (for my menu, header, footer, copyright line, etc.) inside any file in any directory. The idea for using this "links relative to site root" coding came from: http://css-tricks.com/php-include-from-root/
    You will see that it is not just the php include file that is giving me problem, but even the image I placed on the page will not show up online.
    Interestingly, this webpage shows up without problem on my localhost testing server, but (as of this past week) it does not show up properly online.
    I have a virtual host set up as a localhost testing server in the C:\xampp\apache\conf\extra\httpd-vhosts.conf  file like this:
    The setup uses http://site1 as my local host like this:
         <VirtualHost *:80>
           DocumentRoot "c:/users/...../documents/@Websites/dm-webcreation"
           ServerName site1
         </VirtualHost>
    I manage several websites in the same hosting online, so I use "site1" as one website, and "site2" as another website for the local host testing server. In my remote hosting, I host all each website in a different directory of my main hosting (dm-webcreation.com) and point each website's domain name to that directory.
    And this works correctly on my localhost for the website. Both the image file and the php include file show up perfectly.
    My remote server is set up like this Dreamweaver CC2014:
         FTP Address: dm-webcreation.com
          Root Directory:  /dmweb-2/
         Web URL: www.dm-webcreation.com
    My testing server is set up like this in Dreamweaver CC2014 (this matches my VirtualHost set up):
         Server Folder: C:\Users\.....\documents\@Websites\dm-webcreation\
         Web URL: http://site1/
    I do receive this Dreamweaver error when saving the testing server set up:
    The URL prefex "/" of your testing server does not match the URL prefix "/dmweb-2/" of your site. Since you are using site relative links it is possible that your links will display  incorrectly at runtime...
    The strange thing is that I have three websites that were all set up the same way and they all worked fine until I imported them into this new version of Dreamweaver CC2014.
    That's why I am so puzzled. I have created this simple page (www.z.dm-webcreation.com/dmweb-2) just to try to discover what has changed.
    The other websites have the exact same "link relative to site root" in them, but they work without any problem. (www.airpyramid.com , www.leofenton.com ,  www.dev.casacristianavida.com ).
    Either something in my hosting has changed or Dreamweaver's Site Manager works differently...
    I AM REALLY PUZZLED!!

  • PHP-Remote Code Execution

    Hi Experts,
    My IPS has been reporting "PHP-Remote Code Execution" attack on one of our webserver for a while now. Each time the attackers IP address keeps changing. I created an object-group and access-list to deny the object-group on my firewall and i keep adding the attacker's IPs to the group, however i keep recieving new "PHP-Remote Code Execution" attacks. My IPS is in promiscous mode and i have auto signature update enabled.
    IPS has reported "packet denied by global correlation in some case. Like i said, IPS is in promiscous mode. Signature: 2271/0 and CVE-2012-1823
    Apart from making sure the webservers have the right security patches, What else should i be doing?. Do not want to miss anything out?

    cactus wrote:mhakali. I applaud your attention to security.
    However, it is generally not well received to post the same thing in multiple categories..
    Yes. Please do not cross-post: http://bbs.archlinux.org/viewtopic.php?p=205922
    Use the above  thread for discussion.
    Locking.

  • Crypto code needed

    Dear All,
    I'm using SUNFIREV1280, Soloris 8, Fort 7 for C++ compiler.
    Any one can tell me how to get and download crypto (encryption as AES, DES, RC4......HMAC_SHA1 HMAC_MD5.....) library code written in C or C++ which is compatible to my platform to compile without problems?
    Thank in advance

    OpenSSL is very complicated for me.
    I couldn't separate the crypto code and compile it , which is in openssl/crypto files. If any one can separate it for me and compile it in solaris platform i will be very thankful. Im still searching for other library, CryptoSys library is very usefull and simple to use but it only working on Linux not in solaris.
    Hope any one can help.

  • One file  Encrypt in VB using 3DES how to  Decrypt in Java ?

    one file Encrypt in VB using 3DES how to Decrypt in Java ?
    plese give me code
    shrinath

    My problem is something similar to him, but mine is in Tandem C. I have a encrypted text, which was encrypted in Tandem C using OpenSSL. I used CBC mode with no padding, i just wrote the encrypted text to a file & i tried reading the cipher from a Java program, so as to decrypt using the same CBC mode & no padding mode. but it is not decrypted as intended to be.
    can u pls give ur comment? if u have any code can u pls share it here?

  • Help about opening a PHP page from a Java application

    Hi,
    I would have some elements to open a PHP page from a little Java application I'm doing. I would like to know the classes I had to use, how to implement them, ...
    In fact, I dial into my application my login, my password, and when I click on by "Connect" button, I must show the PHP page corresponding ti my profile onto the database. Picking up information from the database is not a problem, I know how to use SQL Packages in Java. The problem is to open a new page (IE or Netscape) when clicking on the "Connect" button in my application.
    Thanks a lot for advice me.
    C�dric

    Hi
    This class is from JavaWorld Tip 66 and I've used it to open web pages and files in a browser.
    import java.io.IOException;
    import java.util.*;
    * A simple, static class to display a URL in the system browser.
    * Under Unix, the system browser is hard-coded to be 'netscape'.
    * Netscape must be in your PATH for this to work.  This has been
    * tested with the following platforms: AIX, HP-UX and Solaris.
    * Under Windows, this will bring up the default browser under windows,
    * usually either Netscape or Microsoft IE.  The default browser is
    * determined by the OS.  This has been tested under Windows 95/98/NT.
    * Examples:
    BrowserControl.displayURL("http://www.javaworld.com")
    BrowserControl.displayURL("file://c:\\docs\\index.html")
    BrowserContorl.displayURL("file:///user/joe/index.html");
    * Note - you must include the url type -- either "http://" or
    * "file://".
    public class BrowserControl
         * Display a file in the system browser.  If you want to display a
         * file, you must include the absolute path name.
         * @param url the file's url (the url must start with either "http://"
    or
         * "file://").
        public static void displayURL(String url) throws Exception
            boolean windows = isWindowsPlatform();
            String cmd = null;
            try
                if (windows)
                    // cmd = 'rundll32 url.dll,FileProtocolHandler http://...'
                    cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
                    Process p = Runtime.getRuntime().exec(cmd);
                else
                    // Under Unix, Netscape has to be running for the "-remote"
                    // command to work.  So, we try sending the command and
                    // check for an exit value.  If the exit command is 0,
                    // it worked, otherwise we need to start the browser.
                    // cmd = 'netscape -remote openURL(http://www.javaworld.com)'
                    cmd = UNIX_PATH + " " + UNIX_FLAG + "(" + url + ")";
                    Process p = Runtime.getRuntime().exec(cmd);
                    try
                        // wait for exit code -- if it's 0, command worked,
                        // otherwise we need to start the browser up.
                        int exitCode = p.waitFor();
                        if (exitCode != 0)
                            // Command failed, start up the browser
                            // cmd = 'netscape http://www.javaworld.com'
                            cmd = UNIX_PATH + " "  + url;
                            p = Runtime.getRuntime().exec(cmd);
                    catch(InterruptedException x)
                        System.err.println("Error bringing up browser, cmd='" +
                                           cmd + "'");
                        System.err.println("Caught: " + x);
                        throw x;
            catch(IOException x)
                // couldn't exec browser
                System.err.println("Could not invoke browser, command=" + cmd);
                System.err.println("Caught: " + x);
                throw x;
         * Try to determine whether this application is running under Windows
         * or some other platform by examing the "os.name" property.
         * @return true if this application is running under a Windows OS
        public static boolean isWindowsPlatform()
            String os = System.getProperty("os.name");
            if ( os != null && os.startsWith(WIN_ID))
                return true;
            else
                return false;
         * Simple example.
        public static void main(String[] args)
          try
    //        displayURL("file://c:\\Manual\\Amphibian Accounting Help Test 3.pdf");
    //        displayURL("http://www.pro7.co.za");
            Properties prop = System.getProperties();
    //        Enumeration enum = prop.propertyNames();
            Enumeration enum = prop.keys();
            while(enum.hasMoreElements())
              enum.nextElement();
          catch(Exception e)
        // Used to identify the windows platform.
        private static final String WIN_ID = "Windows";
        // The default system browser under windows.
        private static final String WIN_PATH = "rundll32";
        // The flag to display a url.
        private static final String WIN_FLAG = "url.dll,FileProtocolHandler";
        // The default browser under unix.
        private static final String UNIX_PATH = "netscape";
        // The flag to display a url.
        private static final String UNIX_FLAG = "-remote openURL";
    }If you find a better solution please let me know!
    Regards
    Michael Williams

  • Php crypt pendent in java

    Hi,
    I need to imitate the php crypt()-function in java.
    I am using the bouncycastle library, but have no idea
    how to realize the same result as with the php crypt() function.
    Can anyone give me some hints how to do that?
    Thanks a lot,
    Andreas.

    See the code at http://locutus.kingwoodcable.com/jfd/crypt.html
    Regards,
    Dimitri

  • Hot Code Replace Problem...

    Hi Everyone,
    I am using WebLogic 10 with Eclipse. Whenever i start the server in debug mode and make two three changes in the code... WHAM.... I get the Hot Code Replace error. Is there any way so that the server can keep up with the code changes. Publishing the app again takes approx 40 mins!

    Almost always this is a limitation of the JRE/JDK you are using and really
    nothing to do with Eclipse.
    Try a different VM and see if you have better luck
    HTH
    Darins
    "bobz" <[email protected]> wrote in message
    news:75257188f239cb376da31e19b214d2d9$[email protected]..
    > hi buddies,
    >
    > i am getting "hot code replace" problem whenever i change my
    > java code and build the project and access the website without re-starting
    > the server. so, finally i endup with re-starting the server whenever i
    > change the code. this consumes a lot of time. is there any possibility to
    > work without re-starting the server even after the code change.
    >
    > regards,
    > satish.

  • Java Shapefile Converter Charset | NLS_LANG | Encoding-Problem

    Hi Forum,
    I tried to use the Java Shapefile Converter and it works fine except of a small, decisive detail.
    I use a Oracle 11 database.
    I'm from Germany and we use characters like ä, ö and ü in our language.
    In the Shapefile, which I'd like to import to the database, are these characters, too.
    So I tried to set the NLS_LANG to 'GERMAN_GERMANY.UTF8' or 'GERMAN_GERMANY.WE8ISO8859P1' but it doesn't work.
    In the table the characters after the import look like a rotated question mark.
    Has anyone an idea?
    Kind regards from Germany
    Edited by: 910195 on 25.01.2012 06:40
    Hi,
    it works with -Dfile.encoding=ISO-8859-1
    Edited by: 910195 on 30.01.2012 06:37

    What is the characterset of your database ?
    What is the column datatype in which you are storing your data ?
    While selecting the data (after insertion) did you set your NLS_LANG ?
    Are you able to view your data properly via any Unicode tool such as SQL developer ?

  • Hi,  We use a Mac os window. How can we get Adobe error code 16 problems in premier cs5. Before 6 da

    Hi,
    We use a Mac os window. How can we get Adobe error code 16 problems in premier cs5. Before 6 days premier does not loaded a Audio.
    please help me.

    I think you are posting to the wrong forum.  I'd post this in the Premier forum: http://forums.adobe.com/community/premiere/premierepro_current
    -Carl V.

  • Java Shapefile Converter in 11g

    I am looking for documentation on how to compile and run the Java Shapefile Converter that is supposedly included with Oracle 11g Spatial (referenced here: http://www.oracle.com/technology/software/products/spatial/index.html).
    I haven't been able to find anything about it other than this post: Updated "Oracle Java Shapefile Converter"? which only pretty much says it is included and no longer a separate download. The readme that is mentioned at the end of the thread (http://www.oracle.com/technology/software/products/spatial/files/text_files/shape2sdojava_readme.txt) is only for 10g and I haven't been able to adapt it for 11g.
    I also found a sample ShapefileToSDO file here: http://www.oracle.com/technology/sample_code/products/spatial/htdocs/sdoapi_samples/sdoapi_samples_readme.html#2
    which may work but I am unable to get it to compile. The command it mentions is:
    javac sample/*.java sample/adapter/*.java
    but it isn't finding a lot of packages needed. I am not sure what classpath to use. I tried putting ojdbc6.jar, sdooutl.jar and sdoapi.jar in the classpath and compiling but the same package error messages came up:
    "C:\sdoapi_samples>javac -classpath C:\JC_CLASSPATH\ojdbc14.jar;C:\JC_CLASSPATH\sdooutl.jar;C:\JC_CLASSPATH\sdoapi.jar C:\sdoapi_samples\sample/*.java C:\sdoapi_samples\sample/adapter/*.java
    sample\SampleShapefileToSDO.java:7: package oracle.sql does not exist
    import oracle.sql.STRUCT;
    ^
    sample\SampleShapefileToSDO.java:8: package oracle.jdbc.driver does not exist
    import oracle.jdbc.driver.*;
    ^
    sample\SampleShapefileToSDO.java:9: package oracle.sdoapi does not exist
    import oracle.sdoapi.OraSpatialManager;
    ^
    sample\SampleShapefileToSDO.java:10: package oracle.sdoapi.geom does not exist
    import oracle.sdoapi.geom.*;
    ^
    sample\SampleShapefileToSDO.java:11: package oracle.sdoapi.adapter does not exis
    t
    import oracle.sdoapi.adapter.GeometryAdapter;
    ^
    sample\adapter\AdapterShapefile.java:6: package oracle.sdoapi does not exist
    import oracle.sdoapi.OraSpatialManager;
    ^
    sample\adapter\AdapterShapefile.java:7: package oracle.sdoapi.adapter does not e
    xist
    import oracle.sdoapi.adapter.*;
    ^
    sample\adapter\AdapterShapefile.java:8: package oracle.sdoapi.geom does not exis
    t
    import oracle.sdoapi.geom.*;
    ^
    sample\adapter\AdapterShapefile.java:9: package oracle.sdoapi.sref does not exis
    t
    import oracle.sdoapi.sref.*;
    ^"...................................................
    it goes on and on with 100 errors total. I am not sure what I am missing.
    Thanks a lot!
    Edited by: user12055867 on Oct 26, 2009 5:18 AM
    Edited by: user12055867 on Oct 26, 2009 5:24 AM

    After setting up my classpath with sdoutl.jar, sdoapi.jar and ojdbc6.jar, I ran the command:
    java -cp %CLASSPATH% oracle.spatial.util.SampleShapefileToJGeomFeature -h host -p port -s orcl -u username -d password -t table -f filename -r 8307
    It worked successfully, the data was entered into the DB. Unfortunately, something is wrong with it. In uDig I cannot view it due to some rendering problem and after running some validation tests on it, I saw the errors:
    1. 'Geometry is required to be a LineString' for all the object names in the table
    I next opened mapbuilder and loaded the same shapefile into the database under the same SRID using mapbuilder's shapefile import. in uDig, this table displayed correctly with no problems!
    I followed the usage instructions for SampleShapefileToJGeom and don't see any other options which would fix this. Am I doing something wrong?
    Edited by: user12055867 on Oct 28, 2009 6:26 AM
    Edited by: user12055867 on Oct 28, 2009 6:26 AM
    Edited by: user12055867 on Oct 28, 2009 6:55 AM

Maybe you are looking for