/// <exception cref="Sharpen.NoSuchAlgorithmException"></exception> /// <exception cref="System.IO.IOException"></exception> public virtual byte[] Sign(Stream stream, DigestAlgorithm digestAlgo, IDssPrivateKeyEntry keyEntry) { if (SignatureAlgorithm.RSA == keyEntry.GetSignatureAlgorithm()) { IDigest digester = DigestUtilities.GetDigest(digestAlgo.GetName()); byte[] buffer = new byte[4096]; int count = 0; while ((count = stream.Read(buffer, 0, buffer.Length)) > 0) { digester.BlockUpdate(buffer, 0, count); } byte[] digestValue = DigestUtilities.DoFinal(digester); return EncryptDigest(digestValue, digestAlgo, keyEntry); } else { //jbonilla throw new System.NotImplementedException("Implementar cuando no es RSA"); //Sharpen.Signature signature = Sharpen.Signature.GetInstance(keyEntry.GetSignatureAlgorithm // ().GetJavaSignatureAlgorithm(digestAlgo)); //try //{ // signature.InitSign(((KSPrivateKeyEntry)keyEntry).GetPrivateKey()); // byte[] buffer = new byte[4096]; // int count = 0; // while ((count = stream.Read(buffer)) > 0) // { // signature.Update(buffer, 0, count); // } // byte[] signValue = signature.Sign(); // return signValue; //} //catch (SignatureException e) //{ // throw new RuntimeException(e); //} //catch (InvalidKeyException e) //{ // throw new RuntimeException(e); //} } }
/// <exception cref="Sharpen.NoSuchAlgorithmException"></exception> /// <exception cref="System.IO.IOException"></exception> public virtual byte[] Sign(Stream stream, DigestAlgorithm digestAlgo, IDssPrivateKeyEntry keyEntry) { if (SignatureAlgorithm.RSA == keyEntry.GetSignatureAlgorithm()) { IDigest digester = DigestUtilities.GetDigest(digestAlgo.GetName()); byte[] buffer = new byte[4096]; int count = 0; while ((count = stream.Read(buffer, 0, buffer.Length)) > 0) { digester.BlockUpdate(buffer, 0, count); } byte[] digestValue = DigestUtilities.DoFinal(digester); return(EncryptDigest(digestValue, digestAlgo, keyEntry)); } else { //jbonilla throw new System.NotImplementedException("Implementar cuando no es RSA"); //Sharpen.Signature signature = Sharpen.Signature.GetInstance(keyEntry.GetSignatureAlgorithm // ().GetJavaSignatureAlgorithm(digestAlgo)); //try //{ // signature.InitSign(((KSPrivateKeyEntry)keyEntry).GetPrivateKey()); // byte[] buffer = new byte[4096]; // int count = 0; // while ((count = stream.Read(buffer)) > 0) // { // signature.Update(buffer, 0, count); // } // byte[] signValue = signature.Sign(); // return signValue; //} //catch (SignatureException e) //{ // throw new RuntimeException(e); //} //catch (InvalidKeyException e) //{ // throw new RuntimeException(e); //} } }
public virtual TimeStampResponse GetTimeStampResponse(DigestAlgorithm algorithm, byte[] digest) { this.digestAlgorithm = algorithm.GetName(); byte[] respBytes = null; TimeStampRequestGenerator tsqGenerator = new TimeStampRequestGenerator(); tsqGenerator.SetCertReq(true); // tsqGenerator.setReqPolicy("1.3.6.1.4.1.601.10.3.1"); BigInteger nonce = BigInteger.ValueOf(DateTime.Now.Ticks + Environment.TickCount); TimeStampRequest request = tsqGenerator.Generate(DigestAlgorithms.GetAllowedDigests(digestAlgorithm), digest, nonce); byte[] requestBytes = request.GetEncoded(); // Call the communications layer respBytes = GetTSAResponse(requestBytes); // Handle the TSA response return(new TimeStampResponse(respBytes)); }
public byte[] Sign(Stream stream, DigestAlgorithm digestAlgo, IDssPrivateKeyEntry keyEntry) { byte[] signedBytes; if (keyEntry is KSX509Certificate2Entry) { var cert = ((KSX509Certificate2Entry)keyEntry).Cert2; X509Certificate2Signature signer = new X509Certificate2Signature(cert, digestAlgo.GetName()); signedBytes = signer.Sign(Streams.ReadAll(stream)); stream.Close(); return(signedBytes); } throw new ArgumentException("Only allowed KSX509Certificate2Entry", "keyEntry"); }