question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Code result different between "vscode" and "intellij idea"

See original GitHub issue

here is the code, about 3DES encryption

import java.security.Key;
import java.util.Base64;

import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;

public class Main {

    static String key = "693207DB8148FBC9D8410179";
    static String iv = "20190225";
    static String encoding = "gb2312";
    static String data = "{\"parkCode\":\"1\",\"plateNo\":\"京A11113\"}";

    
    public static String encrypt(String data) throws Exception {
        DESedeKeySpec keySpec = new DESedeKeySpec(key.getBytes());
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("desede");
        Key deskey = keyFactory.generateSecret(keySpec);

        Cipher cipher = Cipher.getInstance("desede/CBC/PKCS5Padding");
        IvParameterSpec ips = new IvParameterSpec(iv.getBytes());
        cipher.init(Cipher.ENCRYPT_MODE, deskey, ips);
        byte[] encryptData = cipher.doFinal(data.getBytes(encoding));
        return Base64.getEncoder().encodeToString(encryptData);
    }

    public static void main(String[] args) throws Exception {
        System.out.println(encrypt(data));
    }

}

in vscode, the result is

image

0edFaLw+X+9J2LHbzKQa0zo3RGmHII0JhagfRQLJhEVodBeA8XO6rw==

in intellij idea, the result is : image

0edFaLw+X+9J2LHbzKQa0zo3RGmHII0JXoSLu19d+/pvYydg1qZV5A==

I checked the class file, the Main.class in vscode size is 2KB.

The Main.class size in 'intellij idea` is 3KB.

Here is the file: two classes.zip

Please check the problem, thank you for your time.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
itsHobbescommented, Nov 12, 2019

@15050050972 From the two compiled classes you attached you can see this; Intellij compiled class:

{\"parkCode\":\"1\",\"plateNo\":\"?A11113\"}

Vscode compiled class:

{\"parkCode\":\"1\",\"plateNo\":\"??11113\"}

Note the “A” seems to be read incorrectly so I assume some kind of character encoding issue.

So I opened the files with a hex editor and converted them to UTF-8, the issue becomes clear. Using UTF-8, the vscode compiled file the plate number is 浜珹11113 whereas in intellij it is 京A11113. I do not believe this is an issue with vscode, on my end it has no trouble reading those characters.

0reactions
joye-wangcommented, Jan 7, 2020

I found the reason

PS E:\workspace\kotlin\leetcode> cd "e:\workspace\kotlin\leetcode\" ; if ($?) { javac Main.java } ; if ($?) { java Main }
0edFaLw+X+9J2LHbzKQa0zo3RGmHII0JhagfRQLJhEVodBeA8XO6rw==

PS E:\workspace\kotlin\leetcode> cd "e:\workspace\kotlin\leetcode\" ; if ($?) { javac Main.java -encoding utf-8 } ; if ($?) { java Main }
0edFaLw+X+9J2LHbzKQa0zo3RGmHII0JXoSLu19d+/pvYydg1qZV5A==

PS E:\workspace\kotlin\leetcode> cd "e:\workspace\kotlin\leetcode\" ; if ($?) { javac Main.java -encoding gbk } ; if ($?) { java Main }  
0edFaLw+X+9J2LHbzKQa0zo3RGmHII0JhagfRQLJhEVodBeA8XO6rw==

I need use -encoding option to specify the encoding of java file, otherwise javac will get default encoding from OS, my OS is windows, and I’m in China. So my default encoding is GBK

Read more comments on GitHub >

github_iconTop Results From Across the Web

IntelliJ IDEA vs. Visual Studio Code - G2
IntelliJ IDEA rates 4.6/5 stars with 2,002 reviews. By contrast, Visual Studio Code rates 4.7/5 stars with 1,915 reviews. Each product's score is...
Read more >
How to see Visual Studio Code in comparison to JetBrains ...
IntelliJ is a full IDE which comes with 'everything' (intellisense, debugger etc) and VS Code is just a text editor. True, there are...
Read more >
IntelliJ IDEA vs Microsoft Visual Studio Code | TrustRadius
Compare IntelliJ IDEA vs Microsoft Visual Studio Code. 1002 verified user reviews and ratings of features, pros, cons, pricing, support and more.
Read more >
Visual Studio Code vs IntelliJ IDEA – Which is best for Java ...
The reasons are quite clear. Not only is VS Code (still) unsuitable for larger enterprise-level projects, it is also less reliable, responsive ......
Read more >
Comparing Rust IDEs: IntelliJ IDEA, VS Code, and more
Let's look at seven of the best Rust IDEs and code editors, along with useful packages and plugins like IntelliJ Rust.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found