public lr_document() { // TOS = new lr_TOS(); active = true; doc_type = new lr_doc_type.resource_data(); doc_version = new lr_doc_version.v_0_23_0(); identity = new lr_identity(); keys = new lr_keys(); payload_placement = new lr_payload_placement.inline(); payload_schema = new lr_payload_schema(); resource_data = ""; resource_data_type = new lr_resource_data_type.metadata(); resource_locator = ""; payload_schema_locator = ""; payload_schema_format = ""; payload_locator = ""; weight = 100; resource_TTL = 0; digital_signature = null; }
public lr_document Sign(lr_document document) { //Nullify any previous signature info or fields populated by the server document.digital_signature = null; //Bencode the document data string bencodedMsg = document.Bencode(); //Clear sign the bencoded document string clearSignedMessage = signEnvelopeData(getHash(bencodedMsg)); //Create a signature based on the clearSignedMessage lr_digital_signature signature = new lr_digital_signature(); signature.signing_method = signingMethod; Console.WriteLine("message: " + clearSignedMessage); signature.signature = clearSignedMessage; signature.key_location = _publicKeyLocation; //Add the signature to the original document document.digital_signature = signature; return document; }
public lr_document Sign(lr_document document) { //Nullify any previous signature info or fields populated by the server document.digital_signature = null; //Bencode the document data string bencodedMsg = document.Bencode(); //Clear sign the bencoded document string clearSignedMessage = signEnvelopeData(getHash(bencodedMsg)); //Create a signature based on the clearSignedMessage lr_digital_signature signature = new lr_digital_signature(); signature.signing_method = signingMethod; Console.WriteLine("message: " + clearSignedMessage); signature.signature = clearSignedMessage; signature.key_location = _publicKeyLocation; //Add the signature to the original document document.digital_signature = signature; return(document); }
public void Sign(string passphrase, string keyID, string keyloc) { string data = Bencode(); string randomname = System.IO.Path.GetRandomFileName(); randomname = System.IO.Path.GetTempPath() + randomname; try { System.Security.Cryptography.SHA256 sha256 = System.Security.Cryptography.SHA256.Create(); byte[] buffer = System.Text.Encoding.UTF8.GetBytes(data); byte[] hash = sha256.ComputeHash(buffer); System.IO.StreamWriter sw = new System.IO.StreamWriter(randomname + ".json.bencoded"); sw.Write(hash); sw.Close(); string pgpfilename = LearningRegistry.Settings.LR_Integration_GPGLocation() + "gpg.exe"; string arguements; if (keyID == "") { arguements = " -b -a --passphrase-fd 0 " + "\"" + randomname + ".json.bencoded" + "\""; } else { arguements = "--default-key " + keyID + " -b -a --passphrase-fd 0 " + "\"" + randomname + ".json.bencoded" + "\""; } System.Diagnostics.ProcessStartInfo sfi = new System.Diagnostics.ProcessStartInfo(pgpfilename, arguements); sfi.RedirectStandardInput = true; sfi.CreateNoWindow = true; sfi.UseShellExecute = false; System.Diagnostics.Process p = System.Diagnostics.Process.Start(sfi); p.StandardInput.WriteLine(passphrase); p.WaitForExit(); if (p.ExitCode != 0) { throw new Exception("GPG.exe returned code " + p.ExitCode.ToString()); } System.IO.StreamReader sr = new System.IO.StreamReader(randomname + ".json.bencoded.asc"); string sig = sr.ReadToEnd(); sr.Close(); System.IO.File.Delete(randomname + ".json.bencoded.asc"); System.IO.File.Delete(randomname + ".json.bencoded"); digital_signature = new lr_digital_signature(); digital_signature.key_location.Add(keyloc); digital_signature.signature = sig; digital_signature.signing_method = Taxonomies.SigningMethod.LR_PGP_1_0; } catch (Exception) { try { System.IO.File.Delete(randomname + ".json.bencoded.asc"); } catch { } try { System.IO.File.Delete(randomname + ".json.bencoded"); } catch (Exception) { } // throw e; } }