// Arr := Arr.CreateInstance(GETDOTNETTYPE(Type),2); // Arr.SetValue(GETDOTNETTYPE(String),0); // Arr.SetValue(GETDOTNETTYPE(Int),1); // // Arr2 := Arr2.CreateInstance(GETDOTNETTYPE(Type),2); // Arr2.SetValue(GETDOTNETTYPE(String),0); // Arr2.SetValue(GETDOTNETTYPE(Int),1); // // Type := GETDOTNETTYPE(Dict); // Type := Type.MakeGenericType(Arr); // // Dict := Activator.CreateInstance(Type); // Dict.Add('test123',0); //Swapped to using Array of Bytes as above was the wrong type Arr := Arr.CreateInstance(GETDOTNETTYPE(Type),2); Arr.SetValue(GETDOTNETTYPE(Byte),0); Arr.SetValue(GETDOTNETTYPE(Int),1); Arr2 := Arr2.CreateInstance(GETDOTNETTYPE(Type),2); Arr2.SetValue(GETDOTNETTYPE(Byte),0); Arr2.SetValue(GETDOTNETTYPE(Int),1); Type := GETDOTNETTYPE(Dict); Type := Type.MakeGenericType(Arr); Dict := Activator.CreateInstance(Type); NavByte := 65; Dict.Add(0,NavByte); Dict.Add(1,NavByte); Dict.Add(2,NavByte); Dict.Add(3,NavByte); X509Cert2 := X509Cert2.X509Certificate2('C:\ros\rct\Castle_PIT1.p12', CertPassword); //MESSAGE('Issuer Name %1 \Issuer %2 \Private Key %3', X509Cert2.IssuerName, X509Cert2.Issuer, FORMAT(X509Cert2.HasPrivateKey)); PrivateKey := X509Cert2.PrivateKey; //MESSAGE(PrivateKey.ToString); RSASign := RSASign.RSAPKCS1SignatureFormatter(PrivateKey); RSASign.SetHashAlgorithm(X509Cert2.GetCertHashString); //***** Important part :smile: //value to be hashed gets passed in here in Arr, signed value is returned to Arr2 Arr2 := RSASign.CreateSignature(Arr); //Reflection/Generics - failed attempt // RSASignType := RSASign.GetType; // MethodInfo := RSASignType.GetMethod('CreateSignature'); // Parameters := Parameters.CreateInstance(GETDOTNETTYPE(RSASignType),0); // Parameters.SetValue(GETDOTNETTYPE(RSASign), 0); // // MethodInvoke := MethodInfo.MakeGenericMethod(Parameters); // Parameters := Parameters.CreateInstance(GETDOTNETTYPE(RSASign),1); // Parameters.SetValue(RSASign, 0); // SignedHashVal := MethodInvoke.Invoke(NullElement, parameters);
Arr := Encoding.Default.GetBytes(PassOrWhatEver)
Answers
The parameter that is expected is either of type Byte[] or HashAlgorithm.
(https://msdn.microsoft.com/en-us/library/system.security.cryptography.dsasignatureformatter(v=vs.110).aspx)
The link also has an example in DotNet code.
I'm having a look at that link just now. Picking up DotNet as I progress this project. I am trying to pass in C/AL text, the code is C/AL rather that C#. I was using a Text variable, switched to type Byte in C/AL with the same result.
Regards
Roddy
vjeko.com/generics-in-net-interop-for-nav-2013/
xStepa
I'm struggling a bit with Generics/Reflection. I've experimented quite a bit and still getting errors regarding types. There are likely a few basic assumptions I've made, needing to learn cryptography concepts at the same time
The Error Message I'm having is
I've marked the code with ***** Important part below, hopefully someone can point me to the next part.
Many Thanks
Roddy
it was just a sample of an heterogenous array (string & int). You have to use the requested type (Byte[]). So you can use one-dimensional Arr.CreateInstance(GETDOTNETTYPE(Byte), 1) or
xStepa
I now have my digital signature. Which is good progress.
Best Regards
Roddy