Я генерирую цифровую подпись, используя следующий код, пожалуйста, предложите получить цифровую подпись уникальной длины для каждого цифрового сертификата?
Security.addProvider(new BouncyCastleProvider());
try {
Signature signature = Signature.getInstance(DIGEST_SHA1);
signature.initSign(privateKey);
signature.update("abc".getBytes("UTF-8"));
// X509Certificate certFromKeystore = (X509Certificate) ks.getCertificate(signName);
X509Certificate certFromKeystore = x509CertificateToSign;
// System.out.println(alias+"***"+certFromKeystore.toString());
List certList = new ArrayList();
CMSTypedData data = new CMSProcessableByteArray("abc".getBytes());
certList.add(certFromKeystore);
Store certs = new JcaCertStore(certList);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
ContentSigner sha1Signer = new JcaContentSignerBuilder(DIGEST_SHA1)
.setProvider("SunMSCAPI").build(privateKey);
gen.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(
new JcaDigestCalculatorProviderBuilder().setProvider(BC_PROVIDER).build())
.build(sha1Signer, certFromKeystore));
gen.addCertificates(certs);
CMSSignedData signedData = gen.generate(data, false);
BASE64Encoder encoder = new BASE64Encoder();
String signedContent = encoder.encode((byte[]) signedData.getSignedContent().getContent());
System.out.println(
"=============Signed content:=============" + "\n" + signedContent + "\n");
String envelopedData = encoder.encode(signedData.getEncoded());
System.out.println("==============Enveloped data===============" + "\n"
+ envelopedData + "==" + envelopedData.length());