public static void Main(String[] args) { string[] dirs = Directory.GetFiles(@"c:\PATHTODOCS", "*"); Org.BouncyCastle.Pkcs.Pkcs12Store store = new Pkcs12Store(new FileStream(KEYSTORE, FileMode.Open), PASSWORD); String alias = ""; ICollection <X509Certificate> chain = new List <X509Certificate>(); // searching for private key foreach (string al in store.Aliases) { if (store.IsKeyEntry(al) && store.GetKey(al).Key.IsPrivate) { alias = al; break; } } AsymmetricKeyEntry pk = store.GetKey(alias); foreach (X509CertificateEntry c in store.GetCertificateChain(alias)) { chain.Add(c.Certificate); } RsaPrivateCrtKeyParameters parameters = pk.Key as RsaPrivateCrtKeyParameters; C2_01_SignHelloWorld app = new C2_01_SignHelloWorld(); foreach (string dir in dirs) { app.Sign(dir, String.Format(dir + ".pdf", 1), chain, parameters, DigestAlgorithms.SHA256, CryptoStandard.CMS, "Food Safety", "Prime Time International"); } }
public static void Main(String[] args) { Pkcs12Store store = new Pkcs12Store(new FileStream(KEYSTORE, FileMode.Open), PASSWORD); String alias = ""; ICollection <X509Certificate> chain = new List <X509Certificate>(); // searching for private key foreach (string al in store.Aliases) { if (store.IsKeyEntry(al) && store.GetKey(al).Key.IsPrivate) { alias = al; break; } } AsymmetricKeyEntry pk = store.GetKey(alias); foreach (X509CertificateEntry c in store.GetCertificateChain(alias)) { chain.Add(c.Certificate); } RsaPrivateCrtKeyParameters parameters = pk.Key as RsaPrivateCrtKeyParameters; C2_01_SignHelloWorld app = new C2_01_SignHelloWorld(); app.Sign(SRC, String.Format(DEST, 1), chain, parameters, DigestAlgorithms.SHA256, CryptoStandard.CMS, "Test 1", "Ghent"); app.Sign(SRC, String.Format(DEST, 2), chain, parameters, DigestAlgorithms.SHA512, CryptoStandard.CMS, "Test 2", "Ghent"); app.Sign(SRC, String.Format(DEST, 3), chain, parameters, DigestAlgorithms.SHA256, CryptoStandard.CADES, "Test 3", "Ghent"); app.Sign(SRC, String.Format(DEST, 4), chain, parameters, DigestAlgorithms.RIPEMD160, CryptoStandard.CADES, "Test 4", "Ghent"); }