用Bouncy Castle复制Java中的'openssl smime'? [英] Replicating 'openssl smime' in Java with Bouncy Castle?

查看:230
本文介绍了用Bouncy Castle复制Java中的'openssl smime'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我手头有问题。我的不了解Java的同事正在使用OpenSSL命令对文件进行如下签名:

I have a problem in hand. My colleague who doesn't know Java is using OpenSSL commands to sign a file as follows:

openssl smime -binary -sign -certfile WWDR.pem -signer passcertificate.pem \
  -inkey passkey.pem -in manifest.json -out signature -outform DER \
  -passin pass:12345

正如您所看到的,这里有三个文件可供openssl命令生成签名。

As you can see there are three files here that are given to the openssl command to generate the signature.

现在我们想要使用Java复制相同的功能,因为我们假设要签名的内容将是动态的,并且本质上是服务器端的。我读到BouncyCastle是要走的路。但我不知道如何使用该库。我对密码技术也不是很熟悉。我无法理解如何使用上面的所有三个文件来签署 manifest.json 中的内容。

Now we want to replicate the same functionality using Java because the content that we are suppose to be signed will be dynamic and is server side in nature. I read that BouncyCastle is the way to go. But I am not sure how to go about using that library. I am not very familiar with cryptography technologies too. I am not able to understand how do I use all the three files above to sign the content in manifest.json.

如果有人可以指导我找到合适的代码或给我一个开始,我将非常感谢你的努力。

If someone can please guide me to the right code or give me a start I will be very appreciative of your efforts.

推荐答案

所以,如果有人想知道我是如何解决上面的问题,我就是这样做的:

So if someone is wondering how I solved my problem above here is what I did:

我使用的是Java的运行时对象!

I used Java's Runtime object!

String openSSLCommand = openssl smime -binary 
-sign -certfile WWDR.pem -signer passcertificate.pem
-inkey passkey.pem -in manifest.json -out signature -outform DER
-passin pass:12345

Process process = Runtime.getRuntime().exec(openSSLCommand);

谢谢大家

这篇关于用Bouncy Castle复制Java中的'openssl smime'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆