コード例 #1
0
        public void ParseBuffer()
        {
            AssertNextValueIs(SequenceTag);

            byte       prefixLength = TakeBuffer();
            BigInteger bodyLength   = EncodingUtility.CalculateValue(TakeBuffer(2));

            int bufferLen = byteBuffer.Count();

            if (!bodyLength.Equals(bufferLen))
            {
                ThrowFormatException(bodyLength, bufferLen);
            }

            AssertNextValueIs(IntTag);
            AssertNextValueIs(0x01);
            AssertNextValueIs(Version0);

            Modulus  = GetNextVariableValue();
            Exponent = GetNextVariableValue();
            D        = GetNextVariableValue();
            P        = GetNextVariableValue();
            Q        = GetNextVariableValue();
            DP       = GetNextVariableValue();
            DQ       = GetNextVariableValue();
            InverseQ = GetNextVariableValue();
        }
コード例 #2
0
 private static string[] ExtractPQ(RSAParameters key)
 {
     return(new string[]
     {
         EncodingUtility.CalculateValue(key.P).ToString(),
         EncodingUtility.CalculateValue(key.Q).ToString()
     });
 }
コード例 #3
0
 public static void WriteXMLDocument(StringBuilder stringBuilder, RSAParameters key)
 {
     stringBuilder.AppendLine($"<RSAKeyValue>");
     stringBuilder.AppendLine($"  <Modulus>{EncodingUtility.CalculateValue(key.Modulus)}</Modulus>");
     stringBuilder.AppendLine($"  <Exponent>{EncodingUtility.CalculateValue(key.Exponent)}</Exponent>");
     stringBuilder.AppendLine($"  <P>{EncodingUtility.CalculateValue(key.P)}</P>");
     stringBuilder.AppendLine($"  <Q>{EncodingUtility.CalculateValue(key.Q)}</Q>");
     stringBuilder.AppendLine($"  <DP>{EncodingUtility.CalculateValue(key.DP)}</DP>");
     stringBuilder.AppendLine($"  <DQ>{EncodingUtility.CalculateValue(key.DQ)}</DQ>");
     stringBuilder.AppendLine($"  <InverseQ>{EncodingUtility.CalculateValue(key.InverseQ)}</InverseQ>");
     stringBuilder.AppendLine($"  <D>{EncodingUtility.CalculateValue(key.D)}</D>");
     stringBuilder.AppendLine($"</RSAKeyValue>");
     stringBuilder.Append(Environment.NewLine);
 }
コード例 #4
0
        private BigInteger GetNextVariableValue()
        {
            AssertNextValueIs(IntTag);
            int  readSize     = 0;
            byte variableSize = TakeBuffer();

            if (variableSize > 127)
            {
                if (variableSize.Equals(0x81))
                {
                    readSize = TakeBuffer();
                }
                else if (variableSize.Equals(0x82))
                {
                    readSize = (int)EncodingUtility.CalculateValue(TakeBuffer(2));
                }
                else if (variableSize.Equals(0x83))
                {
                    readSize = (int)EncodingUtility.CalculateValue(TakeBuffer(3));
                }
                else if (variableSize.Equals(0x84))
                {
                    readSize = (int)EncodingUtility.CalculateValue(TakeBuffer(4));
                }
                else
                {
                    throw new OverflowException("This class does not support parsing integers with a byte size greater than int.MaxValue");
                }
            }
            else
            {
                readSize = variableSize;
            }

            byte peek = PeekBuffer();

            if (peek.Equals(0x00))
            {
                TakeBuffer();
                readSize--;
            }

            byte[]     variableBytes = TakeBuffer(readSize);
            BigInteger variableValue = EncodingUtility.CalculateValue(variableBytes);

            variableBytes = null;
            return(variableValue);
        }