相关疑难解决方法(0)

设置默认的Java字符编码?

如何以编程方式正确设置JVM(1.5.x)使用​​的默认字符编码?

我已经读过-Dfile.encoding=whatever以前用于旧JVM的方法......由于我不会进入的原因,我没有那么奢侈.

我试过了:

System.setProperty("file.encoding", "UTF-8");
Run Code Online (Sandbox Code Playgroud)

并且属性已设置,但它似乎不会导致下面的最终getBytes调用使用UTF8:

    System.setProperty("file.encoding", "UTF-8");

    byte inbytes[] = new byte[1024];

    FileInputStream fis = new FileInputStream("response.txt");
    fis.read(inbytes);
    FileOutputStream fos = new FileOutputStream("response-2.txt");
    String in = new String(inbytes, "UTF8");
    fos.write(in.getBytes());
Run Code Online (Sandbox Code Playgroud)

java utf-8 character-encoding

342
推荐指数
10
解决办法
62万
查看次数

Java 3DES 实现(学术)

到目前为止我的代码是:

public class TripleDES {
    /**
     * @param args the command line arguments
     * @throws java.security.NoSuchAlgorithmException
     * @throws javax.crypto.NoSuchPaddingException
     * @throws java.security.InvalidKeyException
     * @throws javax.crypto.IllegalBlockSizeException
     * @throws javax.crypto.BadPaddingException
     */
    public static void main(String[] args) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
        //Encrypt: C = EK3(DK2(EK1(P)))
        //Decrypt: P = DK3(EK2(DK1(C)))
        
        Scanner sc = new Scanner(System.in);
        
        //Generate key for DES
        KeyGenerator keyGenerator = KeyGenerator.getInstance("DES");
        SecretKey secretKey = keyGenerator.generateKey();
        SecretKey secretKey2 = keyGenerator.generateKey();
        SecretKey secretKey3 = keyGenerator.generateKey();
        
        //Text Enc & Dec
        Cipher cipher …
Run Code Online (Sandbox Code Playgroud)

java encryption 3des cryptography des

2
推荐指数
1
解决办法
63
查看次数

标签 统计

java ×2

3des ×1

character-encoding ×1

cryptography ×1

des ×1

encryption ×1

utf-8 ×1