示例#1
0
        /// <summary>ハッシュ化</summary>
        private void button11_Click(object sender, EventArgs e)
        {
            this.textBox12.Text = "";
            this.textBox13.Text = "";

            if (this.textBox11.Text == "")
            {
                return;
            }

            // ハッシュ(キー無し)サービスプロバイダ
            HashAlgorithm ha = this.CreateHashAlgorithmServiceProvider();

            // 元文字列
            string ss = this.textBox11.Text;

            //元文字列をbyte型配列に変換する(UTF-8 Enc)
            byte[] asb = Encoding.UTF8.GetBytes(ss);

            // ハッシュ値を計算する
            byte[] hb = ha.ComputeHash(asb);

            //結果を表示

            // 生バイト
            this.textBox12.Text = CustomEncode.ToHexString(hb);
            // Base64
            this.textBox13.Text = Convert.ToBase64String(hb);
        }
示例#2
0
        /// <summary>ハッシュ化</summary>
        private void button21_Click(object sender, EventArgs e)
        {
            this.textBox22.Text = "";
            this.textBox23.Text = "";

            if (this.textBox21a.Text == "" || this.textBox21b.Text == "")
            {
                return;
            }

            // ハッシュ(キー付き)サービスプロバイダ
            KeyedHashAlgorithm kha = this.CreateKeyedHashAlgorithmServiceProvider();

            // 元文字列
            string ss = this.textBox21a.Text;

            // 元文字列をbyte型配列に変換する(UTF-8 Enc)
            byte[] asb = Encoding.UTF8.GetBytes(ss);

            // キー文字列
            string ks = this.textBox21b.Text;

            // キー文字列をbyte型配列に変換する(UTF-8 Enc)
            byte[] akb = Encoding.UTF8.GetBytes(ks);

            // ハッシュ値を計算する
            if (kha is HMACSHA1)
            {
                // どのサイズのキーでも受け入れる
                kha.Key = akb;
            }
            else if (kha is MACTripleDES)
            {
                // 長さが 16 または 24 バイトのキーを受け入れる
                if (akb.Length < 16)
                {
                    MessageBox.Show("キーの長さが不足しています。");
                    return;
                }
                else if (akb.Length < 24)
                {
                    kha.Key = PubCmnFunction.ShortenByteArray(akb, 16);
                }
                else
                {
                    // 24バイトに切り詰め
                    kha.Key = PubCmnFunction.ShortenByteArray(akb, 24);
                }
            }

            byte[] hb = kha.ComputeHash(asb);

            //結果を表示

            // 生バイト
            this.textBox22.Text = CustomEncode.ToHexString(hb);
            // Base64
            this.textBox23.Text = Convert.ToBase64String(hb);
        }
示例#3
0
        /// <summary>秘密鍵・暗号化</summary>
        private void button31_Click(object sender, EventArgs e)
        {
            this.textBox32.Text = "";
            this.textBox33.Text = "";
            this.textBox34.Text = "";

            if (this.textBox31a.Text == "" || this.textBox31b.Text == "")
            {
                return;
            }

            // 元文字列
            string ss = this.textBox31a.Text;

            // 元文字列をbyte型配列に変換する(UTF-8 Enc)
            byte[] asb = Encoding.UTF8.GetBytes(ss);

            // キー文字列
            string ks = this.textBox31b.Text;

            // キー文字列をbyte型配列に変換する(UTF-8 Enc)
            byte[] akb = Encoding.UTF8.GetBytes(ks);

            // 秘密鍵・暗号化サービスプロバイダを生成、初期化
            SymmetricAlgorithm sa = this.CreateSymmetricAlgorithmServiceProvider();

            this.SetKeyAndInitializationVectorToSymmetricAlgorithmServiceProvider(sa, akb);

            // データ出力先メモリストリーム
            MemoryStream ms = new MemoryStream();

            // 暗号化オブジェクトの作成
            ICryptoTransform ict = sa.CreateEncryptor();

            // メモリストリームを暗号化ストリームで装飾
            CryptoStream cs = new CryptoStream(ms, ict, CryptoStreamMode.Write);

            // 暗号化ストリーム⇒メモリストリームに書き込む
            cs.Write(asb, 0, asb.Length);
            cs.FlushFinalBlock();

            // 暗号をメモリストリームから取得
            byte[] acb = ms.ToArray();

            // ストリームを閉じる
            cs.Close();
            ms.Close();

            // 結果を表示

            // 生バイト
            this.textBox32.Text = CustomEncode.ToHexString(acb);
            // Base64
            this.textBox33.Text = Convert.ToBase64String(acb);
        }
示例#4
0
 /// <summary>ハッシュ</summary>
 private void btnGetHash_Click(object sender, EventArgs e)
 {
     if (this.rbnHSString.Checked)
     {
         txtHSCode.Text = GetHash.GetHashString(
             txtHSString.Text, (EnumHashAlgorithm)cbxHSPV.SelectedValue);
     }
     else
     {
         txtHSCode.Text = CustomEncode.ToHexString(GetHash.GetHashBytes(
                                                       CustomEncode.StringToByte(txtHSString.Text, CustomEncode.UTF_8), (EnumHashAlgorithm)cbxHSPV.SelectedValue));
     }
 }
示例#5
0
 /// <summary>共通鍵・暗号化</summary>
 private void button4_Click(object sender, EventArgs e)
 {
     if (this.rbnASCString.Checked)
     {
         // String
         this.txtASCCode.Text =
             ASymmetricCryptography.EncryptString(this.txtASCString.Text, this.txtASCPublic.Text);
     }
     else
     {
         // Bytes
         this.txtASCCode.Text =
             CustomEncode.ToHexString(
                 ASymmetricCryptography.EncryptBytes(
                     CustomEncode.StringToByte(this.txtASCString.Text, CustomEncode.UTF_8), this.txtASCPublic.Text));
     }
 }
示例#6
0
        public void ToHexStringTest(byte[] bytes)
        {
            try
            {
                //convert to string using components of Touryo
                string strValue = CustomEncode.ToHexString(bytes);

                //convert to byte unsing components of Touryo
                byte[] bytesValue = CustomEncode.FormHexString(strValue);

                // Check whether it is converted to original byte.
                Assert.AreEqual(bytes, bytesValue);
            }
            catch (Exception ex)
            {
                // Print a stack trace when an exception occurs.
                Console.WriteLine(ex.StackTrace);
                throw;
            }
        }
示例#7
0
        public void FormHexStringTest(string str)
        {
            try
            {
                //convert to byte using components of Touryo
                byte[] results = CustomEncode.FormHexString(str);

                //convert to string unsing components of Touryo
                string strValue = CustomEncode.ToHexString(results);

                // Check whether the two strings are equal.
                Assert.AreEqual(str, strValue);
            }
            catch (Exception ex)
            {
                // Print a stack trace when an exception occurs.
                Console.WriteLine(ex.StackTrace);
                throw;
            }
        }
示例#8
0
 /// <summary>キー付きハッシュ</summary>
 private void btnGetKeyedHash_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txtKHSSalt.Text))
     {
         // ソルト無し
         if (this.rbnKHSString.Checked)
         {
             // String
             this.txtKHSCode.Text =
                 GetKeyedHash.GetKeyedHashString(
                     this.txtKHSString.Text,
                     (EnumKeyedHashAlgorithm)cbxKHSPV.SelectedValue,
                     this.txtKHSPassword.Text);
         }
         else
         {
             // Bytes
             this.txtKHSCode.Text =
                 CustomEncode.ToHexString(
                     GetKeyedHash.GetKeyedHashBytes(
                         CustomEncode.StringToByte(txtKHSString.Text, CustomEncode.UTF_8),
                         (EnumKeyedHashAlgorithm)cbxKHSPV.SelectedValue,
                         this.txtKHSPassword.Text));
         }
     }
     else
     {
         // ソルト有り
         if (this.nudKHSStretching.Value == 0)
         {
             // ストレッチング無し
             if (this.rbnKHSString.Checked)
             {
                 // String
                 this.txtKHSCode.Text =
                     GetKeyedHash.GetKeyedHashString(
                         this.txtKHSString.Text,
                         (EnumKeyedHashAlgorithm)cbxKHSPV.SelectedValue,
                         this.txtKHSPassword.Text,
                         CustomEncode.StringToByte(this.txtKHSPassword.Text, CustomEncode.UTF_8));
             }
             else
             {
                 // Bytes
                 this.txtKHSCode.Text =
                     CustomEncode.ToHexString(
                         GetKeyedHash.GetKeyedHashBytes(
                             CustomEncode.StringToByte(txtKHSString.Text, CustomEncode.UTF_8),
                             (EnumKeyedHashAlgorithm)cbxKHSPV.SelectedValue,
                             this.txtKHSPassword.Text,
                             CustomEncode.StringToByte(this.txtKHSPassword.Text, CustomEncode.UTF_8)));
             }
         }
         else
         {
             // ストレッチング有り
             if (this.rbnKHSString.Checked)
             {
                 // String
                 this.txtKHSCode.Text =
                     GetKeyedHash.GetKeyedHashString(
                         this.txtKHSString.Text,
                         (EnumKeyedHashAlgorithm)cbxKHSPV.SelectedValue,
                         this.txtKHSPassword.Text,
                         CustomEncode.StringToByte(this.txtKHSPassword.Text, CustomEncode.UTF_8),
                         (int)nudKHSStretching.Value);
             }
             else
             {
                 // Bytes
                 this.txtKHSCode.Text =
                     CustomEncode.ToHexString(
                         GetKeyedHash.GetKeyedHashBytes(
                             CustomEncode.StringToByte(txtKHSString.Text, CustomEncode.UTF_8),
                             (EnumKeyedHashAlgorithm)cbxKHSPV.SelectedValue,
                             this.txtKHSPassword.Text,
                             CustomEncode.StringToByte(this.txtKHSPassword.Text, CustomEncode.UTF_8),
                             (int)nudKHSStretching.Value));
             }
         }
     }
 }
示例#9
0
 /// <summary>秘密鍵・暗号化</summary>
 private void button1_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txtSCSalt.Text))
     {
         // ソルト無し
         if (this.rbnSCString.Checked)
         {
             // String
             this.txtSCCode.Text =
                 SymmetricCryptography.EncryptString(
                     this.txtSCString.Text,
                     this.txtSCPassword.Text,
                     (EnumSymmetricAlgorithm)cbxSCPV.SelectedValue);
         }
         else
         {
             // Bytes
             this.txtSCCode.Text =
                 CustomEncode.ToHexString(
                     SymmetricCryptography.EncryptBytes(
                         CustomEncode.StringToByte(txtSCString.Text, CustomEncode.UTF_8),
                         this.txtSCPassword.Text,
                         (EnumSymmetricAlgorithm)cbxSCPV.SelectedValue));
         }
     }
     else
     {
         // ソルト有り
         if (this.nudSCStretching.Value == 0)
         {
             // ストレッチング無し
             if (this.rbnSCString.Checked)
             {
                 // String
                 this.txtSCCode.Text =
                     SymmetricCryptography.EncryptString(
                         this.txtSCString.Text,
                         this.txtSCPassword.Text,
                         (EnumSymmetricAlgorithm)cbxSCPV.SelectedValue,
                         CustomEncode.StringToByte(txtSCSalt.Text, CustomEncode.UTF_8));
             }
             else
             {
                 // Bytes
                 this.txtSCCode.Text =
                     CustomEncode.ToHexString(
                         SymmetricCryptography.EncryptBytes(
                             CustomEncode.StringToByte(txtSCString.Text, CustomEncode.UTF_8),
                             this.txtSCPassword.Text,
                             (EnumSymmetricAlgorithm)cbxSCPV.SelectedValue,
                             CustomEncode.StringToByte(txtSCSalt.Text, CustomEncode.UTF_8)));
             }
         }
         else
         {
             // ストレッチング有り
             if (this.rbnSCString.Checked)
             {
                 // String
                 this.txtSCCode.Text
                     = SymmetricCryptography.EncryptString(
                           this.txtSCString.Text,
                           this.txtSCPassword.Text,
                           (EnumSymmetricAlgorithm)cbxSCPV.SelectedValue,
                           CustomEncode.StringToByte(txtSCSalt.Text, CustomEncode.UTF_8),
                           (int)this.nudSCStretching.Value);
             }
             else
             {
                 // Bytes
                 this.txtSCCode.Text =
                     CustomEncode.ToHexString(
                         SymmetricCryptography.EncryptBytes(
                             CustomEncode.StringToByte(txtSCString.Text, CustomEncode.UTF_8),
                             this.txtSCPassword.Text,
                             (EnumSymmetricAlgorithm)cbxSCPV.SelectedValue,
                             CustomEncode.StringToByte(txtSCSalt.Text, CustomEncode.UTF_8),
                             (int)this.nudSCStretching.Value));
             }
         }
     }
 }
示例#10
0
        /// <summary>パラメタをSQLに変換する。</summary>
        /// <param name="obj">パラメタ</param>
        /// <returns>SQL化したパラメタ</returns>
        public string ConvertParameterToSQL(object obj)
        {
            StringBuilder sb = new StringBuilder();

            if (obj.GetType() == typeof(char))
            {
                switch (this._dbms)
                {
                case DbEnum.DBMSType.SQLServer:
                    // コンバート
                    sb.Append("Convert(" + this._convertString + ", '" + obj.ToString() + "')");
                    break;

                case DbEnum.DBMSType.MySQL:
                case DbEnum.DBMSType.PstGrS:
                    sb.Append("Cast('" + obj.ToString() + "' as " + this._convertString + ")");
                    break;

                case DbEnum.DBMSType.Oracle:
                    sb.Append("TO_CHAR('" + obj.ToString() + "')");
                    break;

                case DbEnum.DBMSType.DB2:
                    sb.Append("CHAR('" + obj.ToString() + "')");
                    break;

                default:
                    throw new NotImplementedException(PublicExceptionMessage.NOT_IMPLEMENTED);
                }
            }
            else if (obj.GetType() == typeof(string))
            {
                switch (this._dbms)
                {
                case DbEnum.DBMSType.SQLServer:
                    // コンバート + サニタイジング

                    // Convert関数は30文字以上の場合、サイズ指定が必要
                    if (obj.ToString().Length == 0)
                    {
                        // 0文字ではエラーになるのでサイズ指定しない。
                        sb.Append(
                            "Convert("
                            + this._convertString + ", '')");
                    }
                    else
                    {
                        // 30文字以上はサイズ指定する(エスケープ前の文字数)。
                        sb.Append(
                            "Convert("
                            + this._convertString + "(" + obj.ToString().Length + "), '"
                            + obj.ToString().Replace("'", "''") + "')");
                    }

                    break;

                case DbEnum.DBMSType.PstGrS:
                    // コンバート + サニタイジング
                    if (obj.ToString().Length == 0)
                    {
                        sb.Append("''");
                    }
                    else
                    {
                        sb.Append(
                            "Cast('"
                            + obj.ToString().Replace("'", "''") + "' as "
                            + this._convertString + ")");
                    }

                    break;

                case DbEnum.DBMSType.Oracle:
                    // コンバート + サニタイジング
                    // Convert the datatype to the specific data type
                    if (obj.ToString().Length == 0)
                    {
                        // Do not use CAST function here because size of the string will be zero
                        sb.Append("To_CHAR('')");
                    }
                    else
                    {
                        //use CAST to
                        sb.Append(
                            "CAST('"
                            + obj.ToString().Replace("'", "''") + "' AS "
                            + this._convertString + "(" + obj.ToString().Length + ")" + ")");
                    }

                    break;

                case DbEnum.DBMSType.MySQL:
                    // コンバート + サニタイジング
                    if (obj.ToString().Length == 0)
                    {
                        sb.Append("Cast('' as " + this._convertString + ")");
                    }
                    else
                    {
                        sb.Append(
                            "Cast('"
                            + obj.ToString().Replace("'", "''") + "' as "
                            + this._convertString + "(" + obj.ToString().Length + "))");
                    }
                    break;

                case DbEnum.DBMSType.DB2:
                    // コンバート + サニタイジング
                    if (obj.ToString().Length == 0)
                    {
                        sb.Append("CAST('' AS CHAR)");
                    }
                    else
                    {
                        sb.Append(
                            "CAST('"
                            + obj.ToString().Replace("'", "''") + "' AS "
                            + this._convertString + "(" + obj.ToString().Length + ")" + ")");
                    }
                    break;

                default:
                    throw new NotImplementedException(PublicExceptionMessage.NOT_IMPLEMENTED);
                }
            }
            else if (obj.GetType() == typeof(byte))
            {
                switch (this._dbms)
                {
                case DbEnum.DBMSType.SQLServer:
                case DbEnum.DBMSType.MySQL:
                    // Hex文字列化
                    sb.Append("0x" + (CustomEncode.ToHexString((new byte[] { (byte)obj })).Replace(" ", "")));
                    break;

                case DbEnum.DBMSType.PstGrS:
                    sb.Append("decode('" + (CustomEncode.ToHexString((byte[])obj).Replace(" ", "")) + "', 'hex')");
                    break;

                case DbEnum.DBMSType.Oracle:
                    sb.Append("hextoraw('" + (CustomEncode.ToHexString((new byte[] { (byte)obj })).Replace(" ", "")) + "')");
                    break;

                case DbEnum.DBMSType.DB2:
                    sb.Append("x'" + (CustomEncode.ToHexString((new byte[] { (byte)obj })).Replace(" ", "")) + "'");
                    break;

                default:
                    throw new NotImplementedException(PublicExceptionMessage.NOT_IMPLEMENTED);
                }
            }
            else if (obj.GetType() == typeof(byte[]))
            {
                switch (this._dbms)
                {
                case DbEnum.DBMSType.SQLServer:
                case DbEnum.DBMSType.MySQL:
                    // Hex文字列化
                    sb.Append("0x" + (CustomEncode.ToHexString((byte[])obj).Replace(" ", "")));
                    break;

                case DbEnum.DBMSType.PstGrS:
                    sb.Append("decode('" + (CustomEncode.ToHexString((byte[])obj).Replace(" ", "")) + "', 'hex')");
                    break;

                case DbEnum.DBMSType.Oracle:
                    sb.Append("hextoraw('" + (CustomEncode.ToHexString((byte[])obj).Replace(" ", "")) + "')");
                    break;

                case DbEnum.DBMSType.DB2:
                    sb.Append("x'" + (CustomEncode.ToHexString((byte[])obj).Replace(" ", "")) + "'");
                    break;

                default:
                    throw new NotImplementedException(PublicExceptionMessage.NOT_IMPLEMENTED);
                }
            }
            else if (obj.GetType() == typeof(DateTime))
            {
                switch (this._dbms)
                {
                case DbEnum.DBMSType.SQLServer:
                case DbEnum.DBMSType.Oracle:
                case DbEnum.DBMSType.MySQL:
                case DbEnum.DBMSType.DB2:
                    // DateTime文字列化
                    sb.Append("'" + ((DateTime)(obj)).ToString(this._dateTimeFormatString) + "'");
                    break;

                case DbEnum.DBMSType.PstGrS:
                    sb.Append("Cast('" + ((DateTime)(obj)).ToString(this._dateTimeFormatString) + "' as date)");
                    break;

                default:
                    throw new NotImplementedException(PublicExceptionMessage.NOT_IMPLEMENTED);
                }
            }
            else if (obj.GetType() == typeof(DBNull))
            {
                switch (this._dbms)
                {
                case DbEnum.DBMSType.SQLServer:
                case DbEnum.DBMSType.PstGrS:
                case DbEnum.DBMSType.Oracle:
                case DbEnum.DBMSType.MySQL:
                case DbEnum.DBMSType.DB2:
                    // NULL
                    sb.Append("NULL");
                    break;

                default:
                    throw new NotImplementedException(PublicExceptionMessage.NOT_IMPLEMENTED);
                }
            }
            else if (obj == null)
            {
                switch (this._dbms)
                {
                case DbEnum.DBMSType.SQLServer:
                case DbEnum.DBMSType.Oracle:
                case DbEnum.DBMSType.MySQL:
                case DbEnum.DBMSType.DB2:
                    // NULL
                    sb.Append("NULL");
                    break;

                case DbEnum.DBMSType.PstGrS:
                    // For Postgre DEFAULT
                    sb.Append("DEFAULT");
                    break;

                default:
                    throw new NotImplementedException(PublicExceptionMessage.NOT_IMPLEMENTED);
                }
            }
            else
            {
                sb.Append(obj.ToString());
            }

            return(sb.ToString());
        }
示例#11
0
        /// <summary>公開鍵・暗号化</summary>
        private void button41_Click(object sender, EventArgs e)
        {
            this.textBox42.Text = "";
            this.textBox43.Text = "";
            this.textBox44.Text = "";

            if (this.textBox41a.Text == "" ||
                this.textBox41b.Text == "" ||
                this.textBox41c.Text == "")
            {
                return;
            }

            try
            {
                // 暗号のbyte型配列
                byte[] acb = null;
                // 元文字列をbyte型配列に変換する(UTF-8 Enc)
                byte[] asb = Encoding.UTF8.GetBytes(this.textBox41a.Text);

                // 公開鍵・暗号化サービスプロバイダ
                AsymmetricAlgorithm aa = this.CreateAsymmetricAlgorithmServiceProvider();
                this.SetKeyAndInitializationVectorToAsymmetricAlgorithmServiceProvider(aa);

                // 公開鍵
                aa.FromXmlString(this.textBox41b.Text);

                if (aa is DSACryptoServiceProvider)
                {
                    DSACryptoServiceProvider dsacsp = (DSACryptoServiceProvider)aa;

                    // 暗号化する
                    throw new NotImplementedException("DSACryptoServiceProviderの共通鍵暗号化はサポートされていません。");
                }
                else if (aa is ECDiffieHellmanCng)
                {
                    ECDiffieHellmanCng ecdhcng = (ECDiffieHellmanCng)aa;

                    // 暗号化する
                    throw new NotImplementedException("ECDiffieHellmanCngの共通鍵暗号化はサポートされていません。");
                }
                else if (aa is ECDsaCng)
                {
                    ECDsaCng ecdsa = (ECDsaCng)aa;

                    // 暗号化する
                    throw new NotImplementedException("ECDsaCngの共通鍵暗号化はサポートされていません。");
                }
                else if (aa is RSACryptoServiceProvider)
                {
                    RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)aa;

                    // 暗号化する(XP以降の場合のみ2項目にTrueを指定し、OAEPパディングを使用できる)
                    acb = rsa.Encrypt(asb, false);
                }

                // 結果を表示

                // 生バイト
                this.textBox42.Text = CustomEncode.ToHexString(acb);
                // Base64
                this.textBox43.Text = Convert.ToBase64String(acb);
            }
            catch (Exception ex)
            {
                // 結果を表示
                this.textBox44.Text = "エラーです。キーを変更した可能性があります。\r\n"
                                      + ex.ToString();
            }
        }
示例#12
0
        /// <summary>署名</summary>
        private void button51_Click(object sender, EventArgs e)
        {
            this.textBox52.Text = "";
            this.textBox53.Text = "";
            this.textBox54.Text = "";
            this.textBox55.Text = "";
            this.textBox56.Text = "";

            if (this.textBox51a.Text == "" ||
                this.textBox51b.Text == "" ||
                this.textBox51c.Text == "")
            {
                return;
            }

            try
            {
                // 公開鍵・暗号化サービスプロバイダ
                AsymmetricAlgorithm aa = this.CreateAsymmetricAlgorithmServiceProvider2();

                // 秘密鍵
                aa.FromXmlString(this.textBox51c.Text);

                // 元文字列をbyte型配列に変換する(UTF-8 Enc)
                byte[] asb = Encoding.UTF8.GetBytes(this.textBox51a.Text);
                // ハッシュ値
                byte[] ahb = null;
                // 署名
                byte[] ab_sign = null;

                if (aa is DSACryptoServiceProvider)
                {
                    // キャスト
                    DSACryptoServiceProvider dsa = (DSACryptoServiceProvider)aa;

                    // DSASignatureFormatterオブジェクトを作成
                    DSASignatureFormatter dsaFormatter = new DSASignatureFormatter(dsa);

                    // 署名の作成に使用するハッシュアルゴリズムを指定し、ハッシュ値を計算
                    if (this.comboBox5.SelectedItem.ToString().IndexOf("SHA1") != -1)
                    {
                        dsaFormatter.SetHashAlgorithm("SHA1");
                        ahb = SHA1.Create().ComputeHash(asb);
                    }

                    // 署名を作成
                    ab_sign = dsaFormatter.CreateSignature(ahb);
                }
                else if (aa is ECDiffieHellmanCng)
                {
                    // キャスト
                    ECDiffieHellmanCng ecdhcng = (ECDiffieHellmanCng)aa;

                    // 署名を作成
                    throw new NotImplementedException("ECDiffieHellmanCng:未実装");
                }
                else if (aa is ECDsaCng)
                {
                    // キャスト
                    ECDsaCng ecdsa = (ECDsaCng)aa;

                    // 署名を作成
                    throw new NotImplementedException("ECDsaCng:未実装");
                }
                else if (aa is RSACryptoServiceProvider)
                {
                    // キャスト
                    RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)aa;

                    // RSAPKCS1SignatureFormatterオブジェクトを作成
                    RSAPKCS1SignatureFormatter rsaFormatter = new RSAPKCS1SignatureFormatter(rsa);

                    // 署名の作成に使用するハッシュアルゴリズムを指定し、ハッシュ値を計算
                    if (this.comboBox5.SelectedItem.ToString().IndexOf("SHA1") != -1)
                    {
                        rsaFormatter.SetHashAlgorithm("SHA1");
                        ahb = SHA1.Create().ComputeHash(asb);
                    }
                    else if (this.comboBox5.SelectedItem.ToString().IndexOf("MD5") != -1)
                    {
                        rsaFormatter.SetHashAlgorithm("MD5");
                        ahb = MD5.Create().ComputeHash(asb);
                    }

                    // 署名を作成
                    ab_sign = rsaFormatter.CreateSignature(ahb);
                }

                // 結果を表示

                // ハッシュ

                // 生バイト
                this.textBox52.Text = CustomEncode.ToHexString(ahb);
                // Base64
                this.textBox53.Text = Convert.ToBase64String(ahb);

                // 署名

                // 生バイト
                this.textBox54.Text = CustomEncode.ToHexString(ab_sign);
                // Base64
                this.textBox55.Text = Convert.ToBase64String(ab_sign);
            }
            catch (Exception ex)
            {
                // 結果を表示
                this.textBox56.Text = "エラーです。キーを変更した可能性があります。\r\n"
                                      + ex.ToString();
            }
        }