Tag: 文件 o

javax.crypto.BadPaddingException:未知块类型

我试图模拟非对称密钥系统。 我使用以下代码生成密钥对,加密,解密密码。 我有一个分布式环境,目前我保存在文件系统中生成的密钥。 我知道这不安全,但仅用于测试目的。 private static SecureRandom random = new SecureRandom(); static { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); } protected synchronized void generateKeys() throws InvalidKeyException, IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException { KeyPairGenerator generator = KeyPairGenerator.getInstance(“RSA”, “BC”); generator.initialize(256, random); KeyPair pair = generator.generateKeyPair(); Key pubKey = pair.getPublic(); Key privKey = pair.getPrivate(); //store public key try { storeKey(pubKey, Constants.KEY_PATH.concat(Constants.SERVER_PREFIX.concat(“-publickey”))); } […]