/// <summary> /// <para>Encrypt text string with an X509 certificate in a file.</para> /// </summary> /// <param name="textToEncrypt"> /// <para>The text to encrypt.</para> /// </param> /// <param name="certFileName"> /// <para>The encryption certificate file path.</para> /// </param> /// <param name="algorithmOid"> /// <para>The encryption algorithm object identifier (OID).</para> /// </param> /// <returns> /// <para>The encrypted text as <see cref="System.String" />.</para> /// </returns> public static string EncryptTextByCertFile( string textToEncrypt, string certFileName, string algorithmOid) { using (PinCollection pin = new PinCollection()) { try { return(NativeTypes.FromNativeString(NativeCommon.FabricEncryptText2( pin.AddObject(textToEncrypt), pin.AddObject(certFileName), pin.AddObject(algorithmOid)))); } catch (Exception ex) { COMException comEx = Utility.TryTranslateExceptionToCOM(ex); if (comEx != null) { throw comEx; } throw; } } }
private static string EncryptValueHelper( string text, string certFilePath, string algorithmOid) { using (var pin = new PinCollection()) { return(StringResult.FromNative(NativeCommon.FabricEncryptText2( pin.AddBlittable(text), pin.AddBlittable(certFilePath), pin.AddBlittable(algorithmOid)))); } }