Leadtools.Dicom Namespace > DicomDataSet Class : CreateSignature Method |
Privacy Enhanced Mail (PEM)
Distinguished Encoding Rules (DER)
Public Key Cryptography Standard (PKCS) #8 PEM
PKCS#8 DER
PKCS#12
Use the parameter password to specify the password if the private key is stored encrypted.
PEM (usually .pem, .cer, or .crt)
DER (usually .cer or .crt)
PKCS#7 PEM (usually .pem)
PKCS#7 DER (usually .p7b or .spc)
PKCS#12 (usually .pfx or .p12)
If more than one digital certificate is stored in the file, the first one will be used.
For the last format (PKCS#12), use the parameter password to specify the password if the digital certificate is stored encrypted. This parameter is ignored for the rest of the formats.
The method will fail if the specified private key does not match the public key of the digital certificate.
public DicomElement CreateSignature( DicomElement item, string privateKeyFile, string certificateFile, string password, string macTransferSyntax, DicomMacAlgorithm macAlgorithm, long[] elementsToSign, DicomSecurityProfile securityProfile )
'Declaration Public Function CreateSignature( _ ByVal item As DicomElement, _ ByVal privateKeyFile As String, _ ByVal certificateFile As String, _ ByVal password As String, _ ByVal macTransferSyntax As String, _ ByVal macAlgorithm As DicomMacAlgorithm, _ ByVal elementsToSign() As Long, _ ByVal securityProfile As DicomSecurityProfile _ ) As DicomElement
'Usage Dim instance As DicomDataSet Dim item As DicomElement Dim privateKeyFile As String Dim certificateFile As String Dim password As String Dim macTransferSyntax As String Dim macAlgorithm As DicomMacAlgorithm Dim elementsToSign() As Long Dim securityProfile As DicomSecurityProfile Dim value As DicomElement value = instance.CreateSignature(item, privateKeyFile, certificateFile, password, macTransferSyntax, macAlgorithm, elementsToSign, securityProfile)
public DicomElement CreateSignature( DicomElement item, string privateKeyFile, string certificateFile, string password, string macTransferSyntax, DicomMacAlgorithm macAlgorithm, long[] elementsToSign, DicomSecurityProfile securityProfile )
ObjectiveC Syntax
function Leadtools.Dicom.DicomDataSet.CreateSignature( item , privateKeyFile , certificateFile , password , macTransferSyntax , macAlgorithm , elementsToSign , securityProfile )
Privacy Enhanced Mail (PEM)
Distinguished Encoding Rules (DER)
Public Key Cryptography Standard (PKCS) #8 PEM
PKCS#8 DER
PKCS#12
Use the parameter password to specify the password if the private key is stored encrypted.
PEM (usually .pem, .cer, or .crt)
DER (usually .cer or .crt)
PKCS#7 PEM (usually .pem)
PKCS#7 DER (usually .p7b or .spc)
PKCS#12 (usually .pfx or .p12)
If more than one digital certificate is stored in the file, the first one will be used.
For the last format (PKCS#12), use the parameter password to specify the password if the digital certificate is stored encrypted. This parameter is ignored for the rest of the formats.
The method will fail if the specified private key does not match the public key of the digital certificate.
The parameter macTransferSyntax specifies the Transfer Syntax in which the Data Elements included in the Message Authentication Code (MAC) calculation should be encoded. This Transfer Syntax must explicitly include the Value Representation (Explicit VR) and it must use the Little Endian Byte ordering. If the specified Transfer Syntax does not fulfill this condition, the method will behave as if the parameter were set to null.
If macTransferSyntax is set to null, the method will use the Transfer Syntax in which the Data Set is currently encoded if this Transfer Syntax fulfills the condition mentioned in the previous paragraph. If it does not, the method will use the Explicit VR Little Endian Transfer Syntax.
You can use the parameter elementsToSign to specify the Data Elements to be covered by the new Digital Signature. These Data Elements, which are indicated by their tags, must be on the root of the Data Set if item is set to null. If item specifies an Item, then they must be located immediately under that Item. Any Tag that doesn't specify an existing Data Element in the expected location will be ignored. Also, any Tag that specifies a Data Element that cannot be signed according to the standard will be ignored as well.
If elementsToSign is set to null, the method will sign all the Data Elements that can be signed according to the standard and that exist on the root of the Data Set, if item is set to null, or immediately under the Item specified by item.
Digital Signature Security Profiles put restrictions and add specifications. For example, the Rivest-Shamir-Adleman (RSA) Security Profiles require the use of RSA encryption. Therefore, the method will fail if one of these Security Profiles is used while the specified keys are DSA keys. Another example is that the Creator and Authorization RSA Digital Signature Profiles require that, as a minimum, certain Data Elements must be signed if they exist. Therefore, if one of these Security Profiles is used, the method will sign any existing Data Element that is required, even if this Data Element is not included in the array specified by elementsToSign.
Public Sub CreateSignature() Dim dicomFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "IMAGE3.dcm") 'Make sure to initialize the DICOM engine, this needs to be done only once 'In the whole application DicomEngine.Startup() Dim ds As DicomDataSet = New DicomDataSet() Using (ds) 'Load DICOM File ds.Load(dicomFileName, DicomDataSetLoadFlags.None) ds.CreateSignature(Nothing, Path.Combine(LEAD_VARS.ImagesDir, "PrivateKey"), Path.Combine(LEAD_VARS.ImagesDir, "Certificate.cer"), _ Nothing, Nothing, DicomMacAlgorithm.Ripemd160, Nothing, DicomSecurityProfile.None) ' Save the signed Data Set ds.Save(Path.Combine(LEAD_VARS.ImagesDir, "Signed.dcm"), DicomDataSetSaveFlags.None) End Using DicomEngine.Shutdown() End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
public void CreateSignature() { string dicomFileName = Path.Combine(LEAD_VARS.ImagesDir, "IMAGE3.dcm"); //Make sure to initialize the DICOM engine, this needs to be done only once //In the whole application DicomEngine.Startup(); using (DicomDataSet ds = new DicomDataSet()) { //Load DICOM File ds.Load(dicomFileName, DicomDataSetLoadFlags.None); ds.CreateSignature(null, Path.Combine(LEAD_VARS.ImagesDir, "PrivateKey"), Path.Combine(LEAD_VARS.ImagesDir, "Certificate.cer"), null, null, DicomMacAlgorithm.Ripemd160, null, DicomSecurityProfile.None); // Save the signed Data Set ds.Save(Path.Combine(LEAD_VARS.ImagesDir, "Signed.dcm"), DicomDataSetSaveFlags.None); } DicomEngine.Shutdown(); } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2