private static async System.Threading.Tasks.Task <ResultType> TaskMain(Fee.Crypt.OnCryptTask_CallBackInterface a_callback_interface, byte[] a_binary, string a_key, Fee.TaskW.CancelToken a_cancel) #endif { ResultType t_ret; { t_ret.binary = null; t_ret.errorstring = null; } try{ //ハッシュの計算。 byte[] t_hash_binary = null; using (System.Security.Cryptography.SHA1Managed t_sha1 = new System.Security.Cryptography.SHA1Managed()){ t_hash_binary = t_sha1.ComputeHash(a_binary); } if (t_hash_binary == null) { t_ret.binary = null; t_ret.errorstring = "Task_CreateSignaturePrivateKey : hash == null"; } else { using (System.Security.Cryptography.RSACryptoServiceProvider t_rsa = new System.Security.Cryptography.RSACryptoServiceProvider()){ t_rsa.FromXmlString(a_key); //証明書作成。 System.Security.Cryptography.RSAPKCS1SignatureFormatter t_formatter = new System.Security.Cryptography.RSAPKCS1SignatureFormatter(t_rsa); t_formatter.SetHashAlgorithm("SHA1"); t_ret.binary = t_formatter.CreateSignature(t_hash_binary); } } }catch (System.Exception t_exception) { t_ret.binary = null; t_ret.errorstring = "Task_CreateSignaturePrivateKey : " + t_exception.Message; } if (a_cancel.IsCancellationRequested() == true) { t_ret.binary = null; t_ret.errorstring = "Task_CreateSignaturePrivateKey : Cancel"; a_cancel.ThrowIfCancellationRequested(); } if (t_ret.binary == null) { if (t_ret.errorstring == null) { t_ret.errorstring = "Task_CreateSignaturePrivateKey : null"; } } return(t_ret); }
private static async System.Threading.Tasks.Task <ResultType> TaskMain(Fee.Crypt.OnCryptTask_CallBackInterface a_callback_interface, byte[] a_binary, int a_index, int a_length, string a_pass, string a_salt, Fee.TaskW.CancelToken a_cancel) #endif { ResultType t_ret; { t_ret.binary = null; t_ret.errorstring = null; } try{ //RijndaelManaged System.Security.Cryptography.RijndaelManaged t_rijndael = new System.Security.Cryptography.RijndaelManaged(); t_rijndael.KeySize = 256; t_rijndael.BlockSize = 128; t_rijndael.Mode = System.Security.Cryptography.CipherMode.CBC; { byte[] t_salt = System.Text.Encoding.UTF8.GetBytes(a_salt); System.Security.Cryptography.Rfc2898DeriveBytes t_derivebyte = new System.Security.Cryptography.Rfc2898DeriveBytes(a_pass, t_salt); t_derivebyte.IterationCount = 1000; t_rijndael.Key = t_derivebyte.GetBytes(t_rijndael.KeySize / 8); t_rijndael.IV = t_derivebyte.GetBytes(t_rijndael.BlockSize / 8); Tool.Log("Key", System.BitConverter.ToString(t_rijndael.Key)); Tool.Log("IV", System.BitConverter.ToString(t_rijndael.IV)); } //TransformFinalBlock using (System.Security.Cryptography.ICryptoTransform t_decryptor = t_rijndael.CreateDecryptor()){ t_ret.binary = t_decryptor.TransformFinalBlock(a_binary, a_index, a_length); } }catch (System.Exception t_exception) { t_ret.binary = null; t_ret.errorstring = "Task_DecryptPass : "******"Task_DecryptPass : Cancel"; a_cancel.ThrowIfCancellationRequested(); } if (t_ret.binary == null) { if (t_ret.errorstring == null) { t_ret.errorstring = "Task_DecryptPass : null"; } } return(t_ret); }
private static async System.Threading.Tasks.Task <ResultType> TaskMain(Fee.Crypt.OnCryptTask_CallBackInterface a_callback_interface, byte[] a_binary, string a_key, Fee.TaskW.CancelToken a_cancel) #endif { ResultType t_ret; { t_ret.binary = null; t_ret.errorstring = null; } try{ using (System.Security.Cryptography.RSACryptoServiceProvider t_rsa = new System.Security.Cryptography.RSACryptoServiceProvider()){ t_rsa.FromXmlString(a_key); t_ret.binary = t_rsa.Decrypt(a_binary, false); } }catch (System.Exception t_exception) { t_ret.binary = null; t_ret.errorstring = "Task_DecryptPrivateKey : " + t_exception.Message; } if (a_cancel.IsCancellationRequested() == true) { t_ret.binary = null; t_ret.errorstring = "Task_DecryptPrivateKey : Cancel"; a_cancel.ThrowIfCancellationRequested(); } if (t_ret.binary == null) { if (t_ret.errorstring == null) { t_ret.errorstring = "Task_DecryptPrivateKey : null"; } } return(t_ret); }
/** 実行。 */ public static Fee.TaskW.Task <ResultType> Run(Fee.Crypt.OnCryptTask_CallBackInterface a_callback_interface, byte[] a_binary, string a_key, Fee.TaskW.CancelToken a_cancel) { return(new Fee.TaskW.Task <ResultType>(() => { return Task_CreateSignaturePrivateKey.TaskMain(a_callback_interface, a_binary, a_key, a_cancel); })); }
/** TaskMain */ #if ((UNITY_5) || (UNITY_WEBGL)) private static ResultType TaskMain(Fee.Crypt.OnCryptTask_CallBackInterface a_callback_interface, byte[] a_binary, string a_key, Fee.TaskW.CancelToken a_cancel)
/** 実行。 */ public static Fee.TaskW.Task <ResultType> Run(Fee.Crypt.OnCryptTask_CallBackInterface a_callback_interface, byte[] a_binary, int a_index, int a_length, string a_pass, string a_salt, Fee.TaskW.CancelToken a_cancel) { return(new Fee.TaskW.Task <ResultType>(() => { return Task_DecryptPass.TaskMain(a_callback_interface, a_binary, a_index, a_length, a_pass, a_salt, a_cancel); })); }
/** TaskMain */ #if ((UNITY_5) || (UNITY_WEBGL)) private static ResultType TaskMain(Fee.Crypt.OnCryptTask_CallBackInterface a_callback_interface, byte[] a_binary, int a_index, int a_length, string a_pass, string a_salt, Fee.TaskW.CancelToken a_cancel)