读公钥密钥库是用keytool生成的,用的类都是java.security.*的) String keyfile = "D:\\ttt\\server.jks "; //密钥库路径 String keyalias = "alice "; //密钥库别名 char[] keypassword = "password ".toCharArray(); //密钥库密码 KeyStore keystore = KeyStore.getInstance( "JKS "); FileInputStream fis = new FileInputStream(keyfile); keystore.load(fis, keypassword); Key pubKey = keystore.getKey(keyalias, keypassword); 取私钥: KeyStore keystore = KeyStore.getInstance( "JKS "); FileInputStream fis = new FileInputStream(keyfile); keystore.load(fis, keypassword); KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry) keystore.getEntry(keyalias, new KeyStore.PasswordProtection(keypassword)); PrivateKey myPrivateKey = pkEntry.getPrivateKey();
一般来说比较少会直接使用PQNED这样保存Key Java另外有提供方法去保存的: KeyPairGenerator generator = KeyPairGenerator.getInstance( "RSA "); generator.initialize(512); KeyPair pair = generator.generateKeyPair(); byte[] encode = pair.getPrivate().getEncoded(); PKCS8EncodedKeySpec pkcs = new PKCS8EncodedKeySpec(encode); PrivateKey privateKey =KeyFactory.getInstance( "RSA ").generatePrivate(pkcs); System.out.println(Arrays.equals(encode, privateKey.getEncoded())); encode = pair.getPublic().getEncoded(); X509EncodedKeySpec x509 = new X509EncodedKeySpec(encode); PublicKey publicKey = KeyFactory.getInstance( "RSA ").generatePublic(x509); System.out.println(Arrays.equals(encode, publicKey.getEncoded()));
to:westarea(彩色的草原) P:AFE74873 Q:B81AD05B N:7E80A8BA75C230E1 E:10001 D:25D928A1F5533BE1 十六进制,加密 "11 "结果是 "6D9D9C9AA284AD9E " 和你加密的结果不一样,请问是什么问题呢?
我客户端加密好的,现在想在服务端解密.服务端用JAVA去解密,那么在已知PQNED的情况该如何去做呢?