从 BigInteger 转换为八位字节?
我正在尝试手动创建 Web 服务调用的签名标签。我从密钥库访问了证书并访问了证书的公钥。我现在在将 RSAKeyValue 转换为 ds:CryptoBinary 类型时遇到问题。代码返回泥数和指数的 Biginteger 值,我正在寻找一种方法或算法将它们转换为八位字节,然后转换为 Bas64。这是我的代码
RSAPublicKey rsaKey = (RSAPublicKey)certificate.getPublicKey();
customSignature.Modulus = rsaKey.getModulus();
customSignature.Exponent = rsaKey.getPublicExponent();
Java 中是否有任何解决方案可用于将整数转换为八位字节表示形式?
I am trying to manually create the signature tag for a web service call. I accessed the certificate from the keystore and accessed the public key for the certificate. I now have the problem in converting the RSAKeyValue to ds:CryptoBinary type. Code returns the Biginteger value for mudulus and exponent and I am looking for a method or algorithm to convert them to octets and then converting to Bas64. Here is my code
RSAPublicKey rsaKey = (RSAPublicKey)certificate.getPublicKey();
customSignature.Modulus = rsaKey.getModulus();
customSignature.Exponent = rsaKey.getPublicExponent();
Is there any solution available in Java for converting the integers to octet representation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 apache commons 编解码器框架尝试以下代码:
Try following code using apache commons codec framework:
不幸的是,modulus.toByteArray() 并没有直接映射到 XML 数字签名的 ds:CryptoBinary 类型,还需要剥离前导零八位字节。在进行 Base64 编码之前,您需要执行以下操作
Unfortunatly,
modulus.toByteArray()
does not map directly to the XML Digital Signature's ds:CryptoBinary type, which also requires stripping leading zero octets. You need to do something like the following, before you do the base64 encoding