Cipher 加解密window正常linux下报错(Cipher encryption and decryption window reports an error under normal Linux)

  • Exception in thread “main” javax.crypto.BadPaddingException: Given final block not properly padded

  • at com.sun.crypto.provider.SunJCE_f.b(DashoA13*..)

  • at com.sun.crypto.provider.SunJCE_f.b(DashoA13*..)

  • at com.sun.crypto.provider.AESCipher.engineDoFinal(DashoA13*..)

  • //防止linux下 随机生成key

  • SecureRandom secureRandom = SecureRandom.getInstance(“SHA1PRNG” );

  • secureRandom.setSeed(keycontent.getBytes());

  • // 根据密钥初始化密钥生成器

  • kgen.init(keyNum, secureRandom);
    参考:https://blog.csdn.net/zhangyucen/article/details/44807559

————————
  • Exception in thread “main” javax.crypto.BadPaddingException: Given final block not properly padded

  • at com.sun.crypto.provider.SunJCE_f.b(DashoA13*..)

  • at com.sun.crypto.provider.SunJCE_f.b(DashoA13*..)

  • at com.sun.crypto.provider.AESCipher.engineDoFinal(DashoA13*..)

  • //Prevent random key generation under Linux
  • SecureRandom secureRandom = SecureRandom.getInstance(“SHA1PRNG” );

  • secureRandom.setSeed(keycontent.getBytes());

  • //Initialize the key generator based on the key
  • kgen.init(keyNum, secureRandom);
    参考:https://blog.csdn.net/zhangyucen/article/details/44807559