예제 #1
0
 /// <summary>
 /// <para>Encrypt text string with an installed X509 certificate.</para>
 /// </summary>
 /// <param name="textToEncrypt">
 /// <para>The text to encrypt.</para>
 /// </param>
 /// <param name="thumbprint">
 /// <para>The thumbprint of encryption certificate.</para>
 /// </param>
 /// <param name="storeName">
 /// <para>The name of certificate store, from which encryption certificate is retrieved.</para>
 /// </param>
 /// <param name="storeLocation">
 /// <para>The certificate store location to retrieve encryption certificate.</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 EncryptText(
     string textToEncrypt,
     string thumbprint,
     string storeName,
     StoreLocation storeLocation,
     string algorithmOid)
 {
     using (PinCollection pin = new PinCollection())
     {
         try
         {
             return(NativeTypes.FromNativeString(NativeCommon.FabricEncryptText(
                                                     pin.AddObject(textToEncrypt),
                                                     pin.AddObject(thumbprint),
                                                     pin.AddObject(storeName),
                                                     (NativeTypes.FABRIC_X509_STORE_LOCATION)storeLocation,
                                                     pin.AddObject(algorithmOid))));
         }
         catch (Exception ex)
         {
             COMException comEx = Utility.TryTranslateExceptionToCOM(ex);
             if (comEx != null)
             {
                 throw comEx;
             }
             throw;
         }
     }
 }
예제 #2
0
 public static string EncryptValue(string thumbprint, string storeLocation, string textToEncrypt)
 {
     using (PinCollection pin = new PinCollection())
     {
         return(NativeTypes.FromNativeString(NativeCommon.FabricEncryptText(
                                                 pin.AddObject(textToEncrypt),
                                                 pin.AddObject(thumbprint),
                                                 pin.AddObject(storeLocation),
                                                 NativeTypes.FABRIC_X509_STORE_LOCATION.FABRIC_X509_STORE_LOCATION_LOCALMACHINE,
                                                 IntPtr.Zero)));
     }
 }
 private static string EncryptTextHelper(
     string text,
     string certThumbPrint,
     string certStoreName,
     StoreLocation storeLocation,
     string algorithmOid)
 {
     using (var pin = new PinCollection())
     {
         return(StringResult.FromNative(NativeCommon.FabricEncryptText(
                                            pin.AddBlittable(text),
                                            pin.AddBlittable(certThumbPrint),
                                            pin.AddBlittable(certStoreName),
                                            (NativeTypes.FABRIC_X509_STORE_LOCATION)storeLocation,
                                            pin.AddBlittable(algorithmOid))));
     }
 }