这是签名的方法
public static String Sign2(String data, String BEISEN_PRIKEY) throws Exception {
// 密钥格式为PKCS1 需要转换为PKCS8才可以使用
byte[] encodeByte = Base64.decodeBase64(BEISEN_PRIKEY);
AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(PKCSObjectIdentifiers.pkcs8ShroudedKeyBag); //PKCSObjectIdentifiers.pkcs8ShroudedKeyBag
ASN1Object asn1Object = ASN1Object.fromByteArray(encodeByte);
PrivateKeyInfo privKeyInfo = new PrivateKeyInfo(algorithmIdentifier, asn1Object);
byte[] pkcs8Bytes = privKeyInfo.getEncoded();
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(pkcs8Bytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA","BC");
PrivateKey key = keyFactory.generatePrivate(keySpec);
Signature signature = Signature.getInstance(SIGN_ALGORITHMS);
signature.initSign(key);
signature.update(data.getBytes(encoding));
return new String(Base64.encodeBase64(signature.sign()));
}
然后控制台报了这个错
java.security.spec.InvalidKeySpecException: java.lang.ClassCastException: org.bouncycastle.asn1.DERSequence cannot be cast to org.bouncycastle.asn1.DERInteger
这个要怎么改的
下面是例子:
uJikVPTRj2m7lg3SBFxQ3HEtap8y3MzKtUW4vhLelnvhhrBdUVusNYog9cIPODMhVRtyUev7Kqqr7E5z0zn8vjhfDLSkT0VYli3ZmDRr/JZZ343TVaqObxG6ZEZHVXzYBZ+pb0aHzR39nk002LGtFM/Qet4vOACqaASAHwvZjv8= AQAB6IgQk8tQY1/AmeYJQT4vIuzVrfAcI8PR2ELfMD05bBrqZ6PjQWdp/gIlYsLq/VL9loxREDd/jY/ThprDymmraQ==
yzoSAq7rUlNxr/Pmr8/f9VpaiBNCXcjdmmFut7Rv2v4HYMNOAXOQG1NQCdi4f2VcriZ2a9CbcvlvL/t7nAiiJw== nd9bWeyMzJtC+XnryKb+e7jOLoS5pjKZ8zkbrPW0WchAY1MqxMoAdVthpJbv0kQZNbBYjSkQ6by/gUDsMy3hGQ== rqU41RV9JUKQcKUpme0Kic8b/dSPNAlqZ0FT5IsrlQa5UG6Gmri1HsZ6Afw8kT6KZx6mpgCfli7FXna/w1eoAQ== 1MAM8T2f/Xjfbz/ZVK6p/smx5RUmjBxdoFkGVMjEc0iY3UwmEnwOokRiLLDWgXlmqHS08Cb02BRnTQhK5sNLbw== f+TRxkKwhmo9G2OL5JWJOJH5Y2vVM4F32EvsCVTNfvlpcYXzwZCAKb//wgWnwco7B9oyRGv44sDIyLo6KVh9sKc4iERJ5q+ZaTHoSU4TX53/mBiA778rhPXVub22IdBDCJ4VOR4WuUT6tQeXXnPIMw57j3Mroj4auNvYc6kHdyE=版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。