Bu, dökümanın eski bir sürümüdür!
İmzalama işlemi genel olarak iki aşamada gerçekleşmektedir. Öncelikle imzacının sertifikasının doğrulanması yapılmaktadır, sonra imza atma işlemi gerçekleşmektedir.
Veriyi imzalama işleminden BaseSignedData sınıfı sorumludur. Bu sınıfa öncelikle addContent(…) fonksiyonu ile imzalanacak veri eklenmelidir. addContent(…) fonksiyonu yalnızca bir kere çağrılmalıdır. İmzalanacak veri addContent(…) ile eklendikten sonra değiştirilemez. addSigner(…) fonksiyonu ile veriye imza bilgileri eklenir.
İmza eklenirken imzanın türü, imzacının sertifikası, imza işlemini gerçekleştirecek kripto nesnesi, varsa ekstra imza özellikleri ve imza üretiminde kullanılması gereken parametreler addSigner(…) fonksiyonuna parametre olarak geçilmelidir. İmza atan örnek kod bloğu:
BaseSignedData bs = new BaseSignedData(); ISignable content = new SignableByteArray("test".getBytes()); bs.addContent(content); HashMap<String, Object> params = new HashMap<String, Object>(); //if the user does not want certificate validation at generating signature,he can add //P_VALIDATE_CERTIFICATE_BEFORE_SIGNING parameter with its value set to false //params.put(EParameters.P_VALIDATE_CERTIFICATE_BEFORE_SIGNING, false); //necessary for certificate validation.By default,certificate validation is done params.put(EParameters.P_CERT_VALIDATION_POLICY, TestConstants.getPolicy()); //By default, QC statement is checked,and signature wont be created if it is not a //qualified certificate. boolean checkQCStatement = TestConstants.getCheckQCStatement(); //Get qualified or non-qualified certificate. ECertificate cert = SmartCardManager.getInstance().getSignatureCertificate(checkQCStatement, !checkQCStatement); BaseSigner signer = SmartCardManager.getInstance().getSigner(TestConstants.getPIN(), cert); //add signer //Since the specified attributes are mandatory for bes,null is given as parameter //for optional attributes bs.addSigner(ESignatureType.TYPE_BES, cert , signer, null, params); SmartCardManager.getInstance().logout(); byte [] signedDocument = bs.getEncoded(); //write the contentinfo to file AsnIO.dosyayaz(signedDocument,TestConstants.getDirectory() + "testdata/BES-1.p7s");
BaseSignedData bs = new BaseSignedData(); ISignable content = new SignableByteArray(ASCIIEncoding.ASCII.GetBytes("test")); bs.addContent(content); Dictionary<String, Object> params_ = new Dictionary<String, Object>(); //if the user does not want certificate validation at generating signature,he can add //P_VALIDATE_CERTIFICATE_BEFORE_SIGNING parameter with its value set to false params_[EParameters.P_VALIDATE_CERTIFICATE_BEFORE_SIGNING] = false; //necessary for certificate validation.By default,certificate validation is done params_[EParameters.P_CERT_VALIDATION_POLICY] = TestConstants.getPolicy(); //By default, QC statement is checked,and signature wont be created if it is not a //qualified certificate. bool checkQCStatement = TestConstants.getCheckQCStatement(); //Get qualified or non-qualified certificate. ECertificate cert = SmartCardManager.getInstance().getSignatureCertificate(checkQCStatement, !checkQCStatement); BaseSigner signer = SmartCardManager.getInstance().getSigner(TestConstants.getPIN(), cert); //add signer //Since the specified attributes are mandatory for bes,null is given as parameter //for optional attributes try { bs.addSigner(ESignatureType.TYPE_BES, cert, signer, null, params_); } catch (CertificateValidationException cve) { Console.WriteLine(cve.getCertStatusInfo().getDetailedMessage()); } SmartCardManager.getInstance().logout(); byte[] signedDocument = bs.getEncoded(); //write the contentinfo to file DirectoryInfo di = Directory.CreateDirectory(TestConstants.getDirectory()+@"\testVerileri"); AsnIO.dosyayaz(signedDocument, di.FullName + @"\BES-1.p7s");