• 大小: 0.02M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-04-27
  • 语言: C#
  • 标签: IOD  

资源简介

 oid转换

Convert OIDs between Dotted Decimal and Hex

资源截图

代码片段和文件信息


//
// This program is async Form wrap around the code from here
//
// OID Conversion
// by Miroslav Stampar
// https://www.codeproject.com/Articles/16468/OID-Conversation
//

using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace OIDConvert
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public byte[] OidStringToByteArray(string oid)
        {
            string[] split = oid.Trim(‘ ‘ ‘.‘).Split(‘.‘);
            List retVal = new List();

            for (int a = 0 b = 0 i = 0; i < split.Length; i++)
            {
                if (i == 0)
                    a = int.Parse(split[0]);
                else if (i == 1)
                    retVal.Add(40 * a + int.Parse(split[1]));
                else
                {
                    b = int.Parse(split[i]);

                    if (b < 128)
                        retVal.Add(b);
                    else
                    {
                        retVal.Add(128 + (b / 128));
                        retVal.Add(b % 128);
                    }
                }
            }

            byte[] temp = new byte[retVal.Count];

            for (int i = 0; i < retVal.Count; i++)
                temp[i] = (byte)retVal[i];

            return temp;

        }

        public string OidByteArrayToString(byte[] oid)
        {
            StringBuilder retVal = new StringBuilder();

            for (int i = 0; i < oid.Length; i++)
            {
                if (i == 0)
                {
                    int b = oid[0] % 40;
                    int a = (oid[0] - b) / 40;
                    retVal.AppendFormat(“{0}.{1}“ a b);
                }
                else
                {
                    if (oid[i] < 128)
                        retVal.AppendFormat(“.{0}“ oid[i]);
                    else
                    {
                        retVal.AppendFormat(“.{0}“
                           ((oid[i] - 128) * 128) + oid[i + 1]);
                        i++;
                    }
                }
            }

            return retVal.ToString();
        }

        private void ConvertToByteArray_Click(object sender System.EventArgs e)
        {
            StringBuilder strBody = new StringBuilder();
            textBoxByteArray.Text = ““;

            foreach (string Line in textBoxDottedDecimal.Text.Replace(“\r\n““\n“).Split(‘\n‘))
            {
              string strTemp = Line.Trim();

                if (strTemp.Length != 0)
                {
                    byte[] bytes = OidStringToByteArray(strTemp);

                    if (cbFormat.Checked)
                    {
                        bool first = true;

                        foreach (byte abyte in bytes)
                        {
                            if (first)
                            {
                                first = false;
                               

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-03-04 16:47  OIDConvert-master\
     文件        5582  2019-03-04 16:47  OIDConvert-master\.gitignore
     文件         178  2019-03-04 16:47  OIDConvert-master\App.config
     文件        6752  2019-03-04 16:47  OIDConvert-master\Form1.Designer.cs
     文件        4890  2019-03-04 16:47  OIDConvert-master\Form1.cs
     文件        5698  2019-03-04 16:47  OIDConvert-master\Form1.resx
     文件         113  2019-03-04 16:47  OIDConvert-master\LICENSE
     文件        3804  2019-03-04 16:47  OIDConvert-master\OIDConvert.csproj
     文件       11264  2019-03-04 16:47  OIDConvert-master\OIDConvert.exe
     文件         511  2019-03-04 16:47  OIDConvert-master\Program.cs
     目录           0  2019-03-04 16:47  OIDConvert-master\Properties\
     文件        1391  2019-03-04 16:47  OIDConvert-master\Properties\AssemblyInfo.cs
     文件        2786  2019-03-04 16:47  OIDConvert-master\Properties\Resources.Designer.cs
     文件        5496  2019-03-04 16:47  OIDConvert-master\Properties\Resources.resx
     文件        1067  2019-03-04 16:47  OIDConvert-master\Properties\Settings.Designer.cs
     文件         242  2019-03-04 16:47  OIDConvert-master\Properties\Settings.settings
     文件         277  2019-03-04 16:47  OIDConvert-master\README.md

评论

共有 条评论