public IHttpActionResult GetHashPorArchivo([FromBody] RequestHashArchivo request) { string sellodigital = String.Empty; byte[] bytesFirmados = null; try { byte[] ClavePrivada = Convert.FromBase64String(request.claveprivada); byte[] bArchivo = Convert.FromBase64String(request.archivo); SecureString lSecStr = new SecureString(); SHA256Managed sham = new SHA256Managed(); lSecStr.Clear(); foreach (char c in request.password.ToCharArray()) { lSecStr.AppendChar(c); } RSACryptoServiceProvider lrsa = OpenSSLKey.DecodeEncryptedPrivateKeyInfo(ClavePrivada, lSecStr); bytesFirmados = lrsa.SignData(bArchivo, sham); } catch (Exception ex) { sellodigital = "Clave privada incorrecta"; return(BadRequest(sellodigital)); } sellodigital = Convert.ToBase64String(bytesFirmados); return(Ok(sellodigital)); }
private void ConvertPrivateToXML() { try { TextXML = XDocument.Parse(OpenSSLKey.PEMKeyToXKMSKey(TextPEM, "").KeyPrivate).ToString(); } catch (Exception e) { TextXML = e.ToString(); } }