用到对接接口时,考虑安全
使用SSL 方式的socket。进行Server和Client之间的文件传输!
同样想知道,已关注.
是可以的,但是Java平台一般都是使用pkcs8格式的
和软件的所有权有关系
是啊,简单易懂
package com.dhs.test;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Signature;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import org.bouncycastle.util.encoders.Hex;
public class RSATest {
public static final String SRC_STRING = "fdsfsfsfsfd";
public static void main(String[] args) {
try {
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
keyPairGenerator.initialize(512);
KeyPair keyPair = keyPairGenerator.generateKeyPair();
RSAPrivateKey rsaPrivateKey = (RSAPrivateKey) keyPair.getPrivate();// 私钥
RSAPublicKey rsaPublicKey = (RSAPublicKey) keyPair.getPublic();// 公钥
String sign = jdkRSASign(rsaPrivateKey, SRC_STRING);
System.out.println("sign:"+sign);
boolean bool = jdkRSACheck(rsaPublicKey, SRC_STRING, sign);
System.out.println(bool);
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// 签名方法
public static String jdkRSASign(RSAPrivateKey rsaPrivateKey, String src) {
String result = null;// 签名结果
try {
// 2.执行签名
PKCS8EncodedKeySpec pkcS8EncodedKeySpec = new PKCS8EncodedKeySpec(
rsaPrivateKey.getEncoded());
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PrivateKey privateKey = keyFactory
.generatePrivate(pkcS8EncodedKeySpec);
Signature signature = Signature.getInstance("MD5withRSA");
signature.initSign(privateKey);
signature.update(src.getBytes("UTF-8"));
result = Hex.toHexString(signature.sign());
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
// 验签名方法
public static boolean jdkRSACheck(RSAPublicKey rsaPublicKey, String src, String sign) {
boolean result = false;
try {
// 2.验证签名
X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(
rsaPublicKey.getEncoded());
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PublicKey publicKey = keyFactory.generatePublic(x509EncodedKeySpec);
Signature signature = Signature.getInstance("MD5withRSA");
signature.initVerify(publicKey);
signature.update(src.getBytes("UTF-8"));
result = signature.verify(Hex.decode(sign));
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
你是不是傻
commons-codec-1.10.jar
//java的生成支付宝的订单的时候会用到,数字签名,Base64加密
看错了,不好意思
我觉得是可以的,licence就相当于签名
留个记号 啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾啾
JDK的版本可能低,不支持
是啊是啊,简单易懂