private void PAdESHandler_OnRemoteSign(object Sender, byte[] Hash, ref byte[] SignedHash) { //aici trebuie sa fac requestul catre transsped si sa intor ref byte[] SignedHash //pentru semnare - //send otp //credentials authorize - cred id, otp, pin, hash //signHash //credentials authorize string[] hashToSign = new[] { Convert.ToBase64String(Hash) }; JsonSerializer serializer = new JsonSerializer(); ErrorLogger errorLogger = new ErrorLogger(); string baseURL = "https://msign-test.transsped.ro/csc/v0/"; CredentialsAuthorizeClient credAuth = new CredentialsAuthorizeClient(serializer, errorLogger, baseURL); InputCredentialsAuthorize inputCredAuth = new InputCredentialsAuthorize() { credentialID = "863971CBC7BF63D49C9F14809FD5A1142B75E9AB", hash = hashToSign, OTP = OTP, PIN = PIN, numSignatures = 1 }; string outputCredAuth = serializer.Serialize(credAuth.GetCredentialsAuthorize(Access_token, inputCredAuth)); OutputCredentialsAuthorize authorize = serializer.Deserialize <OutputCredentialsAuthorize>(outputCredAuth); //sign hash InputSignaturesSignHash inputSignHash = new InputSignaturesSignHash() { credentialID = "863971CBC7BF63D49C9F14809FD5A1142B75E9AB", hash = hashToSign, SAD = authorize.SAD, hashAlgo = "2.16.840.1.101.3.4.2.1", signAlgo = "1.2.840.113549.1.1.11" }; SignHashClient signHashClient = new SignHashClient(serializer, errorLogger, baseURL); string outputSignature = serializer.Serialize(signHashClient.GetSignedHash(Access_token, inputSignHash)); OutputSignaturesSignHash signature = serializer.Deserialize <OutputSignaturesSignHash>(outputSignature); SignedHash = Encoding.UTF8.GetBytes(signature.signatures.FirstOrDefault()); }
private void CAdES_Handler(object Sender, byte[] Hash, ref byte[] SignedHash) { string[] hashToSign = new[] { Convert.ToBase64String(Hash) }; JsonSerializer serializer = new JsonSerializer(); ErrorLogger errorLogger = new ErrorLogger(); InputCredentialsAuthorize inputCredentialsAuthorize = new InputCredentialsAuthorize() { credentialID = credentialsID, hash = hashToSign, numSignatures = 1, OTP = otp, PIN = pin }; CredentialsAuthorizeClient credentialsAuthorizeClient = new CredentialsAuthorizeClient(serializer, errorLogger, baseURL); string response = serializer.Serialize(credentialsAuthorizeClient.GetCredentialsAuthorize(access_token, inputCredentialsAuthorize)); if (response != null && !response.Contains("error")) { OutputCredentialsAuthorize outCredAuth = serializer.Deserialize <OutputCredentialsAuthorize>(response); InputSignaturesSignHash inputSignatures = new InputSignaturesSignHash() { credentialID = credentialsID, hash = hashToSign, hashAlgo = hashAlgo, SAD = outCredAuth.SAD, signAlgo = signAlgo }; SignHashClient signHashClient = new SignHashClient(serializer, errorLogger, baseURL); string signResponse = serializer.Serialize(signHashClient.GetSignedHash(access_token, inputSignatures)); if (!signResponse.Contains("error")) { var signature = serializer.Deserialize <OutputSignaturesSignHash>(signResponse); var signatureResult = signature.signatures.FirstOrDefault(); SignedHash = Encoding.UTF8.GetBytes(signatureResult); } } }
public object Sign(InputAuthorizeSignHash inputAuthSign) { InputCredentialsAuthorize inputCredentialsAuthorize = new InputCredentialsAuthorize() { credentialID = inputAuthSign.credentialsID, numSignatures = inputAuthSign.numSignatures, hash = inputAuthSign.hash, PIN = inputAuthSign.PIN, OTP = inputAuthSign.OTP, clientData = inputAuthSign.clientData, description = inputAuthSign.description }; JsonSerializer serializer = new JsonSerializer(); ErrorLogger errorLogger = new ErrorLogger(); string baseURL = _configuration.GetSection("Transsped").GetSection("BaseURL").Value; CredentialsAuthorizeClient credentialsAuthorizeClient = new CredentialsAuthorizeClient(serializer, errorLogger, baseURL); Microsoft.Extensions.Primitives.StringValues value; string access_token = ""; if (Request.Headers.TryGetValue("Authorization", out value)) { access_token = value.ToString().Replace("Bearer ", ""); } else { OutputError error = new OutputError() { error = "invalid_access_token", error_description = "Invalid access_token" }; return(serializer.Serialize(error)); } string response = serializer.Serialize(credentialsAuthorizeClient.GetCredentialsAuthorize(access_token, inputCredentialsAuthorize)); if (response != null && !response.Contains("error")) { OutputCredentialsAuthorize outCredAuth = serializer.Deserialize <OutputCredentialsAuthorize>(response); InputSignaturesSignHash inputSignatures = new InputSignaturesSignHash() { clientData = inputAuthSign.clientData, credentialID = inputAuthSign.credentialsID, hash = inputAuthSign.hash, hashAlgo = inputAuthSign.hashAlgo, SAD = outCredAuth.SAD, signAlgo = inputAuthSign.signAlgo, signAlgoParams = inputAuthSign.signAlgoParams }; SignHashClient signHashClient = new SignHashClient(serializer, errorLogger, baseURL); //string signResponse = serializer.Serialize(signHashClient.GetSignedHash(access_token, inputSignatures)); return(signHashClient.GetSignedHash(access_token, inputSignatures)); } else { OutputError error = new OutputError() { error = "invalid_access_token", error_description = "Invalid access_token" }; return(error); } }