public static bool _ctor_System_Security_Cryptography_RNGCryptoServiceProvider_System_Security_Cryptography_CspParameters( ) { //Parameters System.Security.Cryptography.CspParameters cspParams = null; //Exception Exception exception_Real = null; Exception exception_Intercepted = null; InterceptionMaintenance.disableInterception( ); try { returnValue_Real = System.Security.Cryptography.RNGCryptoServiceProvider.ctor(cspParams); } catch (Exception e) { exception_Real = e; } InterceptionMaintenance.enableInterception( ); try { returnValue_Intercepted = System.Security.Cryptography.RNGCryptoServiceProvider.ctor(cspParams); } catch (Exception e) { exception_Intercepted = e; } }
static SignatureTests() { var csp = new System.Security.Cryptography.CspParameters(); csp.Flags = System.Security.Cryptography.CspProviderFlags.CreateEphemeralKey; csp.KeyNumber = (int)System.Security.Cryptography.KeyNumber.Signature; _asymmetricKey = new System.Security.Cryptography.RSACryptoServiceProvider(2048, csp); }
/// <summary> /// 解密 /// </summary> public static string RSADecrypt(string ciphertext) { System.Security.Cryptography.CspParameters param = new System.Security.Cryptography.CspParameters(); param.KeyContainerName = MY_TOKEN; using (System.Security.Cryptography.RSACryptoServiceProvider rsa = new System.Security.Cryptography.RSACryptoServiceProvider(param)) { byte[] encryptdata = Convert.FromBase64String(ciphertext); byte[] decryptdata = rsa.Decrypt(encryptdata, false); return(System.Text.Encoding.Default.GetString(decryptdata)); } }
/// <summary> /// 加密 /// </summary> public static string RSAEncryption(string express) { System.Security.Cryptography.CspParameters param = new System.Security.Cryptography.CspParameters(); param.KeyContainerName = MY_TOKEN; using (System.Security.Cryptography.RSACryptoServiceProvider rsa = new System.Security.Cryptography.RSACryptoServiceProvider(param)) { byte[] plaindata = System.Text.Encoding.Default.GetBytes(express); byte[] encryptdata = rsa.Encrypt(plaindata, false); return(Convert.ToBase64String(encryptdata)); } }
/// <summary> /// RSA加密数据 /// </summary> /// <param name="express">要加密数据</param> /// <returns>以加密的字符串</returns> public static string RSAEncryption(string express) { System.Security.Cryptography.CspParameters param = new System.Security.Cryptography.CspParameters(); param.KeyContainerName = KeyContainerName; //密匙容器的名称,保持加密解密一致才能解密成功 using (System.Security.Cryptography.RSACryptoServiceProvider rsa = new System.Security.Cryptography.RSACryptoServiceProvider(param)) { byte[] plaindata = System.Text.Encoding.Default.GetBytes(express); //将要加密的字符串转换为字节数组 byte[] encryptdata = rsa.Encrypt(plaindata, false); //将加密后的字节数据转换为新的加密字节数组 return(Convert.ToBase64String(encryptdata)); //将加密后的字节数组转换为字符串 } }
public static Tuple <string, string> CreateKeyPair() { System.Security.Cryptography.CspParameters cspParams = new System.Security.Cryptography.CspParameters { ProviderType = 1 }; System.Security.Cryptography.RSACryptoServiceProvider rsaProvider = new System.Security.Cryptography.RSACryptoServiceProvider(1024, cspParams); string publicKey = Convert.ToBase64String(rsaProvider.ExportCspBlob(false)); string privateKey = Convert.ToBase64String(rsaProvider.ExportCspBlob(true)); return(new Tuple <string, string>(privateKey, publicKey)); }
/*公開鍵&秘密鍵生成*/ public static string CreateKeys(string containerName) { //CspParametersオブジェクトの作成 System.Security.Cryptography.CspParameters cp = new System.Security.Cryptography.CspParameters(); //キーコンテナ名を指定する cp.KeyContainerName = containerName; //CspParametersを指定してRSACryptoServiceProviderオブジェクトを作成 System.Security.Cryptography.RSACryptoServiceProvider rsa = new System.Security.Cryptography.RSACryptoServiceProvider(cp); //公開鍵をXML形式で取得して返す return(rsa.ToXmlString(false)); }
public static byte[] Encrypt(string publicKey, string data) { System.Security.Cryptography.CspParameters cspParams = new System.Security.Cryptography.CspParameters { ProviderType = 1 }; System.Security.Cryptography.RSACryptoServiceProvider rsaProvider = new System.Security.Cryptography.RSACryptoServiceProvider(cspParams); rsaProvider.ImportCspBlob(Convert.FromBase64String(publicKey)); byte[] plainBytes = System.Text.Encoding.UTF8.GetBytes(data); byte[] encryptedBytes = rsaProvider.Encrypt(plainBytes, false); return(encryptedBytes); }
public static string Decrypt(string privateKey, byte[] encryptedBytes) { System.Security.Cryptography.CspParameters cspParams = new System.Security.Cryptography.CspParameters { ProviderType = 1 }; System.Security.Cryptography.RSACryptoServiceProvider rsaProvider = new System.Security.Cryptography.RSACryptoServiceProvider(cspParams); rsaProvider.ImportCspBlob(Convert.FromBase64String(privateKey)); byte[] plainBytes = rsaProvider.Decrypt(encryptedBytes, false); string plainText = System.Text.Encoding.UTF8.GetString(plainBytes, 0, plainBytes.Length); return(plainText); }
/*キーコンテナ削除*/ public static void DeleteKeys(string containerName) { //CspParametersオブジェクトの作成 System.Security.Cryptography.CspParameters cp = new System.Security.Cryptography.CspParameters(); //キーコンテナ名を指定する cp.KeyContainerName = containerName; //CspParametersを指定してRSACryptoServiceProviderオブジェクトを作成 System.Security.Cryptography.RSACryptoServiceProvider rsa = new System.Security.Cryptography.RSACryptoServiceProvider(cp); //キーコンテナを削除 rsa.PersistKeyInCsp = false; rsa.Clear(); }
/*複合化*/ public static string Decrypt(string str, string containerName) { //CspParametersオブジェクトの作成 System.Security.Cryptography.CspParameters cp = new System.Security.Cryptography.CspParameters(); //キーコンテナ名を指定する cp.KeyContainerName = containerName; //CspParametersを指定してRSACryptoServiceProviderオブジェクトを作成 System.Security.Cryptography.RSACryptoServiceProvider rsa = new System.Security.Cryptography.RSACryptoServiceProvider(cp); //復号化する byte[] data = System.Convert.FromBase64String(str); byte[] decryptedData = rsa.Decrypt(data, false); return(System.Text.Encoding.UTF8.GetString(decryptedData)); }
public string Descriptografar(string chavePrivada, string criptografia) { System.Security.Cryptography.CspParameters config = new System.Security.Cryptography.CspParameters { ProviderType = 1 }; System.Security.Cryptography.RSACryptoServiceProvider rsa = new System.Security.Cryptography.RSACryptoServiceProvider(config); byte[] chavePrivadaBytes = Convert.FromBase64String(chavePrivada); rsa.ImportCspBlob(chavePrivadaBytes); byte[] criptografiaBytes = Convert.FromBase64String(criptografia); byte[] mensagemBytes = rsa.Decrypt(criptografiaBytes, false); string mensagem = Encoding.UTF8.GetString(mensagemBytes); return(mensagem); }
public static void Main(string[] args) { GostCryptoConfig.ProviderType = ProviderTypes.CryptoPro; var keyContainer = new System.Security.Cryptography.CspParameters(); keyContainer.ProviderType = GostCryptoConfig.ProviderType; keyContainer.KeyNumber = 1; keyContainer.KeyContainerName = "REGISTRY\\\\CONTAINER_NAME"; var ss = new System.Security.SecureString(); foreach (char c in "12345678".ToCharArray()) { ss.AppendChar(c); } keyContainer.KeyPassword = ss; GostCryptoConfig.KeyContainerParameters = keyContainer; RunWCFSmev3(); Console.ReadKey(); }
public List <string> GerarChaves() { System.Security.Cryptography.CspParameters cspParams = new System.Security.Cryptography.CspParameters { ProviderType = 1 }; System.Security.Cryptography.RSACryptoServiceProvider rsaProvider = new System.Security.Cryptography.RSACryptoServiceProvider(cspParams); byte[] privateBytes = rsaProvider.ExportCspBlob(true); byte[] publicBytes = rsaProvider.ExportCspBlob(false); string privateKey = Convert.ToBase64String(privateBytes); string publicKey = Convert.ToBase64String(publicBytes); List <string> chaves = new List <string>(); chaves.Add(privateKey); chaves.Add(publicKey); return(chaves); }
public static string Decrypt(string stringToDecrypt, string key) { string result = null; if (string.IsNullOrEmpty(stringToDecrypt)) { //throw new ArgumentException("An empty string value cannot be encrypted."); } if (string.IsNullOrEmpty(key)) { throw new ArgumentException("Cannot decrypt using an empty key. Please supply a decryption key."); } try { System.Security.Cryptography.CspParameters cspp = new System.Security.Cryptography.CspParameters(); cspp.KeyContainerName = key; System.Security.Cryptography.RSACryptoServiceProvider rsa = new System.Security.Cryptography.RSACryptoServiceProvider(cspp); rsa.PersistKeyInCsp = true; string[] decryptArray = stringToDecrypt.Split(new string[] { "-" }, StringSplitOptions.None); byte[] decryptByteArray = Array.ConvertAll <string, byte>(decryptArray, (s => Convert.ToByte(byte.Parse(s, System.Globalization.NumberStyles.HexNumber)))); byte[] bytes = rsa.Decrypt(decryptByteArray, true); result = System.Text.UTF8Encoding.UTF8.GetString(bytes); } catch (Exception ex) { throw new Exception(ex.Message); } finally { // no need for further processing } return(result); }
/// <summary> /// Encryptes a string using the supplied key. Encoding is done using RSA encryption. /// </summary> /// <param name="stringToEncrypt">String that must be encrypted.</param> /// <param name="key">Encryptionkey.</param> /// <returns>A string representing a byte array separated by a minus sign.</returns> /// <exception cref="ArgumentException">Occurs when stringToEncrypt or key is null or empty.</exception> public static string Encrypt(this string stringToEncrypt, string key) { if (string.IsNullOrEmpty(stringToEncrypt)) { throw new ArgumentException("An empty string value cannot be encrypted."); } if (string.IsNullOrEmpty(key)) { throw new ArgumentException("Cannot encrypt using an empty key. Please supply an encryption key."); } System.Security.Cryptography.CspParameters cspp = new System.Security.Cryptography.CspParameters(); cspp.KeyContainerName = key; System.Security.Cryptography.RSACryptoServiceProvider rsa = new System.Security.Cryptography.RSACryptoServiceProvider(cspp); rsa.PersistKeyInCsp = true; byte[] bytes = rsa.Encrypt(System.Text.UTF8Encoding.UTF8.GetBytes(stringToEncrypt), true); return(BitConverter.ToString(bytes)); }
public RSACryptoServiceProvider(System.Security.Cryptography.CspParameters parameters) { }
public CspKeyContainerInfo(System.Security.Cryptography.CspParameters parameters) { }
public PasswordDeriveBytes(string strPassword, byte[] rgbSalt, string strHashName, int iterations, System.Security.Cryptography.CspParameters cspParams) { }
public RNGCryptoServiceProvider(System.Security.Cryptography.CspParameters cspParams) { }
public PasswordDeriveBytes(byte[] password, byte[] salt, System.Security.Cryptography.CspParameters cspParams) { }
public PasswordDeriveBytes(string strPassword, byte[] rgbSalt, System.Security.Cryptography.CspParameters cspParams) { }
public KeyContainerPermissionAccessEntry(System.Security.Cryptography.CspParameters parameters, KeyContainerPermissionFlags flags) { Contract.Requires(parameters != null); Contract.Ensures(((System.Security.Cryptography.CspProviderFlags)(Int32.MinValue)) <= parameters.Flags); Contract.Ensures(parameters.Flags <= ((System.Security.Cryptography.CspProviderFlags)(Int32.MaxValue))); }
internal CspKeyContainerInfo(System.Security.Cryptography.CspParameters parameters, bool randomKeyContainer) { }
public CapiContext(System.Security.Cryptography.CspParameters csp) { }
public CapiHash(System.Security.Cryptography.CspParameters cspParams, int hashAlgorithm) { }
public Gost3410_2012_512CryptoServiceProvider(System.Security.Cryptography.CspParameters parameters) { }
public string encrypt(string publicKey, string plainText) { System.Security.Cryptography.CspParameters cspParams = null; System.Security.Cryptography.RSACryptoServiceProvider rsaProvider = null; byte[] plainBytes = null; byte[] encryptedBytes = null; string result = ""; try { cspParams = new System.Security.Cryptography.CspParameters(); cspParams.ProviderType = 1; rsaProvider = new System.Security.Cryptography.RSACryptoServiceProvider(cspParams); rsaProvider.FromXmlString(publicKey); plainBytes = System.Text.Encoding.UTF8.GetBytes(plainText); encryptedBytes = rsaProvider.Encrypt(plainBytes, false); result = Convert.ToBase64String(encryptedBytes); } catch (Exception ex) { } return result; }
public void generatekeys() { System.Security.Cryptography.CspParameters cspParams = null; System.Security.Cryptography.RSACryptoServiceProvider rsaProvider = null; string publicKey = ""; string privateKey = ""; try { cspParams = new System.Security.Cryptography.CspParameters(); cspParams.ProviderType = 1; cspParams.Flags = System.Security.Cryptography.CspProviderFlags.UseArchivableKey; cspParams.KeyNumber = (int)System.Security.Cryptography.KeyNumber.Exchange; rsaProvider = new System.Security.Cryptography.RSACryptoServiceProvider(cspParams); publicKey = rsaProvider.ToXmlString(false); privateKey = rsaProvider.ToXmlString(true); log("Public Key"); log(publicKey); log(""); log("Private Key"); log(privateKey); tabControlCode.SelectedIndex = 2; } catch (Exception ex) { } }
public KeyContainerPermissionAccessEntry(System.Security.Cryptography.CspParameters parameters, KeyContainerPermissionFlags flags) { }
public DSACryptoServiceProvider(int dwKeySize, System.Security.Cryptography.CspParameters parameters) { }
public CmsSigner(System.Security.Cryptography.CspParameters parameters) { }
/// <summary> /// Returns all of the key containers. /// </summary> private static string[] GetContainerNames() { const int BUFFSIZE = 25600; List<string> containernames = new List<string>(); byte[] pbData = new byte[BUFFSIZE]; int pcbData = BUFFSIZE; int enumflags = (int)PP_ENUMCONTAINERS; // specify container enumeration functionality IntPtr hProv = IntPtr.Zero; int dwFlags = 0; int gotcsp = NativeMethods.CryptAcquireContextW(ref hProv, null, null, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET); if (gotcsp == 0) { int error = Marshal.GetLastWin32Error(); return null; } /* ---------- Get KeyContainer Names ------------- */ dwFlags = (int)CRYPT_FIRST; //required initalization StringBuilder sb = new StringBuilder(BUFFSIZE); int result = 0; do { result = NativeMethods.CryptGetProvParam(hProv, enumflags, sb, ref pcbData, dwFlags); if (result == 0) { int error = Marshal.GetLastWin32Error(); if (ERROR_MORE_DATA != error) { break; } } containernames.Add(sb.ToString()); System.Security.Cryptography.CspParameters csparms = new System.Security.Cryptography.CspParameters(); csparms.KeyContainerName = sb.ToString(); csparms.KeyNumber = AT_KEYEXCHANGE; csparms.Flags = System.Security.Cryptography.CspProviderFlags.UseMachineKeyStore; System.Security.Cryptography.RSACryptoServiceProvider key = new System.Security.Cryptography.RSACryptoServiceProvider(csparms); dwFlags = CRYPT_NEXT; } while (true); if (hProv != IntPtr.Zero) { NativeMethods.CryptReleaseContext(hProv, 0); } return null; }