本文整理汇总了Java中sun.security.pkcs.PKCS7.encodeSignedData方法的典型用法代码示例。如果您正苦于以下问题:Java PKCS7.encodeSignedData方法的具体用法?Java PKCS7.encodeSignedData怎么用?Java PKCS7.encodeSignedData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.security.pkcs.PKCS7
的用法示例。
在下文中一共展示了PKCS7.encodeSignedData方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: signatureBlock
import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
/** Write a .RSA file with a digital signature. */
private static void signatureBlock(
Signature signature,
X509Certificate publicKey,
OutputStream out)
throws IOException, GeneralSecurityException {
SignerInfo signerInfo = new SignerInfo(
new X500Name(publicKey.getIssuerX500Principal().getName()),
publicKey.getSerialNumber(),
AlgorithmId.get("SHA1"),
AlgorithmId.get("RSA"),
signature.sign());
PKCS7 pkcs7 = new PKCS7(
new AlgorithmId[] { AlgorithmId.get("SHA1") },
new ContentInfo(ContentInfo.DATA_OID, null),
new X509Certificate[] { publicKey },
new SignerInfo[] { signerInfo });
System.out.print("\rGenerating signature block...");
pkcs7.encodeSignedData(out);
}
示例2: writeSignatureBlock
import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
/**
* Write the certificate file with a digital signature.
*/
private void writeSignatureBlock(Signature signature, X509Certificate publicKey,
PrivateKey privateKey)
throws IOException, GeneralSecurityException {
SignerInfo signerInfo = new SignerInfo(
new X500Name(publicKey.getIssuerX500Principal().getName()),
publicKey.getSerialNumber(),
AlgorithmId.get(DIGEST_ALGORITHM),
AlgorithmId.get(privateKey.getAlgorithm()),
signature.sign());
PKCS7 pkcs7 = new PKCS7(
new AlgorithmId[]{AlgorithmId.get(DIGEST_ALGORITHM)},
new ContentInfo(ContentInfo.DATA_OID, null),
new X509Certificate[]{publicKey},
new SignerInfo[]{signerInfo});
pkcs7.encodeSignedData(mOutputJar);
}
示例3: writeSignatureBlock
import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
/** Write the certificate file with a digital signature. */
private void writeSignatureBlock(Signature signature, X509Certificate publicKey,
PrivateKey privateKey)
throws IOException, GeneralSecurityException {
SignerInfo signerInfo = new SignerInfo(
new X500Name(publicKey.getIssuerX500Principal().getName()),
publicKey.getSerialNumber(),
AlgorithmId.get(DIGEST_ALGORITHM),
AlgorithmId.get(privateKey.getAlgorithm()),
signature.sign());
PKCS7 pkcs7 = new PKCS7(
new AlgorithmId[] { AlgorithmId.get(DIGEST_ALGORITHM) },
new ContentInfo(ContentInfo.DATA_OID, null),
new X509Certificate[] { publicKey },
new SignerInfo[] { signerInfo });
pkcs7.encodeSignedData(mOutputJar);
}
示例4: writeSignatureBlock
import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
/** Write a .RSA file with a digital signature. */
private static void writeSignatureBlock(
Signature signature, X509Certificate publicKey, OutputStream out)
throws IOException, GeneralSecurityException {
SignerInfo signerInfo = new SignerInfo(
new X500Name(publicKey.getIssuerX500Principal().getName()),
publicKey.getSerialNumber(),
AlgorithmId.get("SHA1"),
AlgorithmId.get("RSA"),
signature.sign());
PKCS7 pkcs7 = new PKCS7(
new AlgorithmId[] { AlgorithmId.get("SHA1") },
new ContentInfo(ContentInfo.DATA_OID, null),
new X509Certificate[] { publicKey },
new SignerInfo[] { signerInfo });
pkcs7.encodeSignedData(out);
}
示例5: writeSignatureBlock
import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
/** Write the certificate file with a digital signature. */
private void writeSignatureBlock(Signature signature, X509Certificate publicKey,
PrivateKey privateKey)
throws IOException, GeneralSecurityException {
SignerInfo signerInfo = new SignerInfo(
new X500Name(publicKey.getIssuerX500Principal().getName()),
publicKey.getSerialNumber(),
AlgorithmId.get(DIGEST_ALGORITHM),
AlgorithmId.get(privateKey.getAlgorithm()),
signature.sign());
PKCS7 pkcs7 = new PKCS7(
new AlgorithmId[] { AlgorithmId.get(DIGEST_ALGORITHM) },
new ContentInfo(ContentInfo.DATA_OID, null),
new X509Certificate[] { publicKey },
new SignerInfo[] { signerInfo });
pkcs7.encodeSignedData(mOutputJar);
}
示例6: encodePKCS7
import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
/**
* Encode the CertPath using PKCS#7 format.
*
* @return a byte array containing the binary encoding of the PKCS#7 object
* @exception CertificateEncodingException if an exception occurs
*/
private byte[] encodePKCS7() throws CertificateEncodingException {
PKCS7 p7 = new PKCS7(new AlgorithmId[0],
new ContentInfo(ContentInfo.DATA_OID, null),
certs.toArray(new X509Certificate[certs.size()]),
new SignerInfo[0]);
DerOutputStream derout = new DerOutputStream();
try {
p7.encodeSignedData(derout);
} catch (IOException ioe) {
throw new CertificateEncodingException(ioe.getMessage());
}
return derout.toByteArray();
}
示例7: signp11NoSignPol
import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
private void signp11NoSignPol() throws Exception {
// LOAD CERT
PrivateKey privateKey = (PrivateKey) pkcs11Ref.getKeyStore().getKey(this.getCertAlias(), "".toCharArray());
X509Certificate certificate = (X509Certificate) pkcs11Ref.getKeyStore().getCertificate(this.getCertAlias());
// Sign data
Signature sig = Signature
.getInstance(DIGITAL_SIGNATURE_ALGORITHM_NAME[0]);
// sha1 only
sig.initSign(privateKey);
BASE64Decoder b64dec = new BASE64Decoder();
BASE64Encoder b64enc = new BASE64Encoder();
sig.update(b64dec.decodeBuffer(orig));
byte[] signedData = sig.sign();
//load X500Name
X500Name xName = X500Name.asX500Name(certificate.getSubjectX500Principal());
//load serial number
BigInteger serial = certificate.getSerialNumber();
//laod digest algorithm
AlgorithmId digestAlgorithmId = new AlgorithmId(AlgorithmId.SHA_oid);
//load signing algorithm
AlgorithmId signAlgorithmId = new AlgorithmId(AlgorithmId.RSAEncryption_oid);
//Create SignerInfo:
SignerInfo sInfo = new SignerInfo(xName, serial, digestAlgorithmId, signAlgorithmId, signedData);
//Create ContentInfo:
// ContentInfo cInfo = new ContentInfo(ContentInfo.DIGESTED_DATA_OID, new DerValue(DerValue.tag_OctetString, dataToSign));
ContentInfo cInfo = new ContentInfo(ContentInfo.DIGESTED_DATA_OID, null);
//Create PKCS7 Signed data
PKCS7 p7 = new PKCS7(new AlgorithmId[] { digestAlgorithmId }, cInfo,
new X509Certificate[]{certificate},
new SignerInfo[] { sInfo });
//Write PKCS7 to bYteArray
ByteArrayOutputStream bOut = new DerOutputStream();
p7.encodeSignedData(bOut);
byte[] encodedPKCS7 = bOut.toByteArray();
result = b64enc.encode(encodedPKCS7);
}
示例8: writeSignatureBlock
import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
private static void writeSignatureBlock(Signature signature, X509Certificate publicKey, OutputStream out)
throws IOException, GeneralSecurityException {
SignerInfo signerInfo = new SignerInfo(new X500Name(publicKey.getIssuerX500Principal().getName()),
publicKey.getSerialNumber(), AlgorithmId.get("SHA1"), AlgorithmId.get("RSA"), signature.sign());
PKCS7 pkcs7 = new PKCS7(new AlgorithmId[] { AlgorithmId.get("SHA1") }, new ContentInfo(ContentInfo.DATA_OID,
null), new X509Certificate[] { publicKey }, new SignerInfo[] { signerInfo });
pkcs7.encodeSignedData(out);
}
示例9: rebuildEnvelope
import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
@Override
public byte[] rebuildEnvelope(byte[] envelope) throws Exception {
// CMSSignedData cms = new CMSSignedData(envelope);
// cms.
//
// SignerInformationStore signers = cms.getSignerInfos();
//
// Collection c = signers.getSigners();
// Iterator it = c.iterator();
//
// while (it.hasNext()) {
// SignerInformation signer = (SignerInformation) it.next();
// SignerId sid = signer.getSID();
//
// Store certs = cms.getCertificates();
// Collection certCollection = certs.getMatches(signer.getSID());
// for (Object next : certCollection) {
// System.out.println(next);
// }
// }
PKCS7 pkcs7 = new PKCS7(envelope);
X509Certificate[] certs = pkcs7.getCertificates();
if (certs.length == 1) {
List<X509Certificate> path = certServ.buildPath(certs[0]);
SignerInfo[] si = pkcs7.getSignerInfos();
// for(X509Certificate next : path){
// System.out.println(next.getSubjectDN().getName());
//
// }
ContentInfo cInfo = new ContentInfo(ContentInfo.DIGESTED_DATA_OID,
null);
AlgorithmId digestAlgorithmId = new AlgorithmId(AlgorithmId.SHA_oid);
X509Certificate[] pathArray = new X509Certificate[path.size()];
int i = 0;
for (X509Certificate next : path) {
pathArray[i] = next;
i++;
}
// Create PKCS7 Signed data
PKCS7 p7 = new PKCS7(new AlgorithmId[] { digestAlgorithmId },
cInfo, pathArray, si);
// Write PKCS7 to bYteArray
ByteArrayOutputStream bOut = new DerOutputStream();
p7.encodeSignedData(bOut);
byte[] encodedPKCS7 = bOut.toByteArray();
return encodedPKCS7;
}
return envelope;
}
示例10: signFileNoSignPol
import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
private void signFileNoSignPol() throws Exception {
System.out.println("signFileNoSignPol");
// LOAD CERT
PrivateKey privateKey = PkiHelper.loadPrivFromP12(
this.lastFilePath, this.userPIN);
X509Certificate certificate = PkiHelper.loadCertFromP12(
this.lastFilePath, this.userPIN);
// Sign data
Signature sig = Signature
.getInstance(DIGITAL_SIGNATURE_ALGORITHM_NAME[0]);
// sha1 only
sig.initSign(privateKey);
BASE64Decoder b64dec = new BASE64Decoder();
BASE64Encoder b64enc = new BASE64Encoder();
sig.update(b64dec.decodeBuffer(orig));
byte[] signedData = sig.sign();
//load X500Name
X500Name xName = X500Name.asX500Name(certificate.getSubjectX500Principal());
//load serial number
BigInteger serial = certificate.getSerialNumber();
//laod digest algorithm
AlgorithmId digestAlgorithmId = new AlgorithmId(AlgorithmId.SHA_oid);
//load signing algorithm
AlgorithmId signAlgorithmId = new AlgorithmId(AlgorithmId.RSAEncryption_oid);
//Create SignerInfo:
SignerInfo sInfo = new SignerInfo(xName, serial, digestAlgorithmId, signAlgorithmId, signedData);
//Create ContentInfo:
// ContentInfo cInfo = new ContentInfo(ContentInfo.DIGESTED_DATA_OID, new DerValue(DerValue.tag_OctetString, dataToSign));
ContentInfo cInfo = new ContentInfo(ContentInfo.DIGESTED_DATA_OID, null);
//Create PKCS7 Signed data
PKCS7 p7 = new PKCS7(new AlgorithmId[] { digestAlgorithmId }, cInfo,
new X509Certificate[]{certificate},
new SignerInfo[] { sInfo });
//Write PKCS7 to bYteArray
ByteArrayOutputStream bOut = new DerOutputStream();
p7.encodeSignedData(bOut);
byte[] encodedPKCS7 = bOut.toByteArray();
result = b64enc.encode(encodedPKCS7);
System.out.println("result:"+result);
}
示例11: signp11NoSignPol
import sun.security.pkcs.PKCS7; //导入方法依赖的package包/类
private void signp11NoSignPol() throws Exception {
// LOAD CERT
PrivateKey privateKey = (PrivateKey) keyStore.getKey(
this.getCertAlias(), "".toCharArray());
X509Certificate certificate = (X509Certificate) keyStore
.getCertificate(this.getCertAlias());
// Sign data
Signature sig = Signature
.getInstance(DIGITAL_SIGNATURE_ALGORITHM_NAME[0]);
// sha1 only
sig.initSign(privateKey);
BASE64Decoder b64dec = new BASE64Decoder();
BASE64Encoder b64enc = new BASE64Encoder();
sig.update(b64dec.decodeBuffer(orig));
byte[] signedData = sig.sign();
//load X500Name
X500Name xName = X500Name.asX500Name(certificate.getSubjectX500Principal());
//load serial number
BigInteger serial = certificate.getSerialNumber();
//laod digest algorithm
AlgorithmId digestAlgorithmId = new AlgorithmId(AlgorithmId.SHA_oid);
//load signing algorithm
AlgorithmId signAlgorithmId = new AlgorithmId(AlgorithmId.RSAEncryption_oid);
//Create SignerInfo:
SignerInfo sInfo = new SignerInfo(xName, serial, digestAlgorithmId, signAlgorithmId, signedData);
//Create ContentInfo:
// ContentInfo cInfo = new ContentInfo(ContentInfo.DIGESTED_DATA_OID, new DerValue(DerValue.tag_OctetString, dataToSign));
ContentInfo cInfo = new ContentInfo(ContentInfo.DIGESTED_DATA_OID, null);
//Create PKCS7 Signed data
PKCS7 p7 = new PKCS7(new AlgorithmId[] { digestAlgorithmId }, cInfo,
new X509Certificate[]{certificate},
new SignerInfo[] { sInfo });
//Write PKCS7 to bYteArray
ByteArrayOutputStream bOut = new DerOutputStream();
p7.encodeSignedData(bOut);
byte[] encodedPKCS7 = bOut.toByteArray();
result = b64enc.encode(encodedPKCS7);
}