在应用程序中使用证书 [英] Using a certificate in an app
本文介绍了在应用程序中使用证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好;
我在我的智能手机中安装了globalsign的数字证书。我想用它来签署PDF文件,但我不知道如何在我的Android应用程序中利用它做我的目的。有人知道怎么做,谢谢。
Hello everybody;
I installs a digital certificate from globalsign in my smartphone.I wants to use it for signing a PDF documents but i don't know how to exploit it in my android application to do my purpose .There is someone who know how to do it and thanks.
推荐答案
我努力解决问题,我找到了这个代码,但他们是一个失踪我不知道如何获取证书目录的事情。
I tried hard to solve the problem ,i found this code but they are a missing thing that i don't know how to get the directory of my certificate.
public static final boolean signPdf()
throws IOException, DocumentException, Exception
{
String fileKey = "???" ;
String fileKeyPassword = "MyPassword" ;
try {
// Creationof KeyStore
KeyStore ks = KeyStore.getInstance("pkcs12");
ks.load(new FileInputStream(fileKey), fileKeyPassword.toCharArray());
String alias = (String)ks.aliases().nextElement();
PrivateKey key = (PrivateKey)ks.getKey(alias, fileKeyPassword.toCharArray());
Certificate[] chain = ks.getCertificateChain(alias);
PdfReader pdfReader = new PdfReader((new File(fname)).getAbsolutePath());
File outputFile = new File(fnameS);
PdfStamper pdfStamper;
pdfStamper = PdfStamper.createSignature(pdfReader, null, '\0', outputFile);
PdfSignatureAppearance sap = pdfStamper.getSignatureAppearance();
sap.setCrypto(key, chain, null, PdfSignatureAppearance.SELF_SIGNED);
sap.setReason("Test SignPDF berthou.mc");
sap.setLocation("");
// Position du tampon sur la page (ici en bas a gauche page 1)
sap.setVisibleSignature(new Rectangle(10, 10, 50, 30), 1, "sign_rbl");
pdfStamper.setFormFlattening(true);
pdfStamper.close();
return true;
}
catch (Exception key) {
throw new Exception(key);
}
}
这篇关于在应用程序中使用证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文