zulin
February 4, 2024, 2:45am
1
How do I sign the signature string of PCKS1 when I already know it?
this is Base64.getEncoder().encodeToString(byte[]) created,How use it to ?
Sw0WzJmleKGFcv9Dpe/z/4NMfndjJbhVYU3niDxzL0UK4ACtYKNA35stPUQ2R8jnLDh+Dn6Yg4NRCJilZv0gKzNcVkaoymPjR2ChZTUSLpAI+h9w+G2VMstgfL5bkoSBvAyogmmnzUD+Rho2+BbHOLFABsig7Z6r+ay/2UDC4JJVxjCXT4HY089/FNeDYeW+D/zooEJnrt7pb4YrolzvjBC3SXKVMcWnB/k1BmS6V1Hlv+yAvc/MqbjEGSttiL9CeNSXUVkjySbzMzGLfvpoiYcI0NXqsJwepnSc6ths/ZuGScDTnH3bR5dO7aSBdYa6tqzwrM3hLQWAxxEBndykuA==
I should use this method setCustomSignHash(Signature.SignHash 值) ?,but my Aspose.PDF for java version is 23.9,I could not find this method,How should I do ?
@zulin
Please spare us little time as we are collecting the related information and will share it with you soon.
zulin
February 5, 2024, 12:55am
3
Ok I writing for your good news
@zulin
We have opened the following new ticket(s) in our internal issue tracking system and will perform investigation for your rquirements.
Issue ID(s): PDFJAVA-43530
We will let you know as soon as it is resolved. Please spare us some time.
@zulin
We don’t have such functionality for PCKS1. We recommend to use PCKS7. Please check if below code snippet helps:
PdfFileSignature sign = new PdfFileSignature();
sign.bindPdf("inputPdf.pdf");
PKCS7 pkcs7 = new PKCS7("inputP12.p12", "inputPfxPassword");
com.aspose.pdf.Signature.SignHash signHashDelegate = pkcs7.new SignHash() {
@Override
public byte[] invoke(byte[] signableHash) {
try {
// Load the P12 certificate
KeyStore keyStore = KeyStore.getInstance("PKCS12");
try (FileInputStream fis = new FileInputStream("inputP12.p12")) {
keyStore.load(fis, "inputPfxPassword".toCharArray());
}
// Get the certificate and private key
String alias = keyStore.aliases().nextElement();
Certificate cert = keyStore.getCertificate(alias);
PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, "inputPfxPassword".toCharArray());
// Create a Signature object with SHA1 algorithm
java.security.Signature signature = java.security.Signature.getInstance("SHA1withRSA");
signature.initSign(privateKey);
// Update the signature with the data to be signed
signature.update(signableHash);
// Generate the signature
return signature.sign();
} catch (Exception e) {
// Log the exception
throw new RuntimeException(e);
}
}
};
pkcs7.setCustomSignHash(signHashDelegate);
sign.sign(1, "reason", "cont", "loc", false, new java.awt.Rectangle(0, 0, 500, 500), pkcs7);
sign.save("outputPdf.pdf");
zulin
February 7, 2024, 2:37am
6
1 I do’t hava a .p12 file and pfx password,so that I can’t finish this signature for my pdf…
zulin
February 7, 2024, 8:58am
7
image.jpg (142.7 KB)
my Asponse.pdf version is 23.9 ,could find com.aspose.pdf.Signature.SignHash this class,should i update version to latest version?
zulin
February 7, 2024, 9:03am
8
I find method in latest version ,ok
@zulin
Yes, the method is available in the latest version and we always recommend using the latest version of the API. Nevertheless, please let us know in case you still have any concerns.