小编use*_*364的帖子

例外:在Linux中"给定最终块未正确填充",但它适用于Windows

我的应用程序在Windows中运行,但在Linux中失败,Given final block not properly padded例外.

组态:

  • JDK版本:1.6
  • Windows:版本7
  • Linux:CentOS 5.8 64位

我的代码如下:

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class SecurityKey {
    private static Key key = null;
    private static String encode = "UTF-8";
    private static String cipherKey = "DES/ECB/PKCS5Padding";

    static  {
        try {
            KeyGenerator generator = KeyGenerator.getInstance("DES");
            String seedStr = "test";
            generator.init(new SecureRandom(seedStr.getBytes()));
            key = generator.generateKey(); …
Run Code Online (Sandbox Code Playgroud)

java encryption

10
推荐指数
1
解决办法
2931
查看次数

标签 统计

encryption ×1

java ×1