public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            int _aal = 0, len;

            // encode transportParameters

            if (transportParameters != null)
            {
                len   = transportParameters.Encode(buffer, false);
                _aal += len;
                _aal += buffer.EncodeTagAndLength(Asn1Tag.CTXT, Asn1Tag.CONS, 0, len);
            }

            // encode sessionEncryptedKey

            len   = sessionEncryptedKey.Encode(buffer, true);
            _aal += len;

            if (explicitTagging)
            {
                _aal += buffer.EncodeTagAndLength(Asn1Tag.Sequence, _aal);
            }

            return(_aal);
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            int _aal = 0, len;

            // encode ukm

            if (!(ukm.Length == 8))
            {
                throw new Exception("Asn1ConsVioException (ukm.Length, ukm.Length)");
            }

            len   = ukm.Encode(buffer, true);
            _aal += len;

            // encode ephemeralPublicKey

            if (ephemeralPublicKey != null)
            {
                len   = ephemeralPublicKey.Encode(buffer, false);
                _aal += len;
                _aal += buffer.EncodeTagAndLength(Asn1Tag.CTXT, Asn1Tag.CONS, 0, len);
            }

            // encode encryptionParamSet

            len   = encryptionParamSet.Encode(buffer, true);
            _aal += len;

            if (explicitTagging)
            {
                _aal += buffer.EncodeTagAndLength(Asn1Tag.Sequence, _aal);
            }

            return(_aal);
        }
Beispiel #3
0
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = 0;

            if (Ukm.Length != 8)
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1ConsVioException, "Ukm.Length", Ukm.Length);
            }

            len += Ukm.Encode(buffer, true);

            if (EphemeralPublicKey != null)
            {
                var epkLength = EphemeralPublicKey.Encode(buffer, false);

                len += epkLength;
                len += buffer.EncodeTagAndLength(0x80, 0x20, EocTypeCode, epkLength);
            }

            len += EncryptionParamSet.Encode(buffer, true);

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Asn1Tag.Sequence, len);
            }

            return(len);
        }
Beispiel #4
0
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = 0;

            if (MacKey.Length != 4)
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1ConsVioException, "MacKey.Length", MacKey.Length);
            }

            var num2 = MacKey.Encode(buffer, true);

            len += num2;

            if (_maskKey != null)
            {
                num2 = _maskKey.Encode(buffer, false);
                len += num2;
                len += buffer.EncodeTagAndLength(0x80, 0, EocTypeCode, num2);
            }

            num2 = EncryptedKey.Encode(buffer, true);
            len += num2;

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Asn1Tag.Sequence, len);
            }

            return(len);
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = 0;

            if (Ukm.Length != 8)
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1ConsVioException, "Ukm.Length", Ukm.Length);
            }

            len += Ukm.Encode(buffer, true);

            if (EphemeralPublicKey != null)
            {
                var epkLength = EphemeralPublicKey.Encode(buffer, false);

                len += epkLength;
                len += buffer.EncodeTagAndLength(0x80, 0x20, EocTypeCode, epkLength);
            }

            len += EncryptionParamSet.Encode(buffer, true);

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Asn1Tag.Sequence, len);
            }

            return len;
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            int _aal = 0, len;

            // encode macKey

            if (!(macKey.Length == 4))
            {
                throw new Exception("Asn1ConsVioException");
            }

            len   = macKey.Encode(buffer, true);
            _aal += len;

            // encode maskKey

            if (maskKey != null)
            {
                len   = maskKey.Encode(buffer, false);
                _aal += len;
                _aal += buffer.EncodeTagAndLength(Asn1Tag.CTXT, Asn1Tag.PRIM, 0, len);
            }

            // encode encryptedKey

            len   = encryptedKey.Encode(buffer, true);
            _aal += len;

            if (explicitTagging)
            {
                _aal += buffer.EncodeTagAndLength(Asn1Tag.Sequence, _aal);
            }

            return(_aal);
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            int _aal = 0, len;

            // encode encryptionParamSet

            if (encryptionParamSet != null)
            {
                len   = encryptionParamSet.Encode(buffer, true);
                _aal += len;
            }

            // encode digestParamSet

            len   = digestParamSet.Encode(buffer, true);
            _aal += len;

            // encode publicKeyParamSet

            len   = publicKeyParamSet.Encode(buffer, true);
            _aal += len;

            if (explicitTagging)
            {
                _aal += buffer.EncodeTagAndLength(Asn1Tag.Sequence, _aal);
            }

            return(_aal);
        }
Beispiel #8
0
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            int _aal = 0, len;

            // encode ukm

            if (ukm != null)
            {
                if (!(ukm.Length == 8))
                {
                    throw new Exception("Asn1ConsVioException");
                }

                len   = ukm.Encode(buffer, true);
                _aal += len;
            }

            // encode encryptionParamSet

            len   = encryptionParamSet.Encode(buffer, true);
            _aal += len;

            if (explicitTagging)
            {
                _aal += buffer.EncodeTagAndLength(Asn1Tag.Sequence, _aal);
            }

            return(_aal);
        }
Beispiel #9
0
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            int _aal = 0, len;

            checkTC(false);
            // encode parameters

            if (parameters != null)
            {
                len   = parameters.Encode(buffer, true);
                _aal += len;
            }

            // encode algorithm

            len   = algorithm.Encode(buffer, true);
            _aal += len;

            if (explicitTagging)
            {
                _aal += buffer.EncodeTagAndLength(Asn1Tag.Sequence, _aal);
            }

            return(_aal);
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = buffer.EncodeIntValue(Value);

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Tag, len);
            }

            return len;
        }
Beispiel #11
0
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = buffer.EncodeIntValue(Value);

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Tag, len);
            }

            return(len);
        }
Beispiel #12
0
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = 0;

            if (TransportParameters != null)
            {
                var tpLength = TransportParameters.Encode(buffer, false);

                len += tpLength;
                len += buffer.EncodeTagAndLength(0x80, 0x20, EocTypeCode, tpLength);
            }

            len += SessionEncryptedKey.Encode(buffer, true);

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Asn1Tag.Sequence, len);
            }

            return(len);
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = 0;

            if (TransportParameters != null)
            {
                var tpLength = TransportParameters.Encode(buffer, false);

                len += tpLength;
                len += buffer.EncodeTagAndLength(0x80, 0x20, EocTypeCode, tpLength);
            }

            len += SessionEncryptedKey.Encode(buffer, true);

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Asn1Tag.Sequence, len);
            }

            return len;
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = 1;

            buffer.Copy(Value ? byte.MaxValue : ((byte)0));

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Tag, len);
            }

            return len;
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = 0;
            len += EncryptedParameters.Encode(buffer, true);
            len += EncryptedKey.Encode(buffer, true);

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Asn1Tag.Sequence, len);
            }

            return len;
        }
Beispiel #16
0
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = 1;

            buffer.Copy(Value ? byte.MaxValue : ((byte)0));

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Tag, len);
            }

            return(len);
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = 0;
            len += SubjectPublicKey.Encode(buffer, true);
            len += Algorithm.Encode(buffer, true);

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Asn1Tag.Sequence, len);
            }

            return len;
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = 0;

            len += SubjectPublicKey.Encode(buffer, true);
            len += Algorithm.Encode(buffer, true);

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Asn1Tag.Sequence, len);
            }

            return(len);
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = 0;

            len += EncryptionParamSet.Encode(buffer, true);
            len += Iv.Encode(buffer, true);

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Asn1Tag.Sequence, len);
            }

            return(len);
        }
Beispiel #20
0
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            if (Length != 0x40)
            {
                throw new Exception("Asn1ConsVioException");
            }
            var len = base.Encode(buffer, false);

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Tag, len);
            }

            return(len);
        }
Beispiel #21
0
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            if ((Length < 1) || (Length > 4))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1ConsVioException, nameof(Length), Length);
            }

            var len = base.Encode(buffer, false);

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Tag, len);
            }

            return(len);
        }
		public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
		{
			if (Length != 32)
			{
				throw ExceptionUtility.CryptographicException(Resources.Asn1ConsVioException, "Length", Length);
			}

			var len = base.Encode(buffer, false);

			if (explicitTagging)
			{
				len += buffer.EncodeTagAndLength(Tag, len);
			}

			return len;
		}
Beispiel #23
0
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            if (!(Length == 8))
            {
                throw new Exception("Asn1ConsVioException (Length, Length)");
            }

            int _aal = base.Encode(buffer, false);

            if (explicitTagging)
            {
                _aal += buffer.EncodeTagAndLength(Tag, _aal);
            }

            return(_aal);
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = 0;

            var num2 = _encryptionParamSet.Encode(buffer, true);
            len += num2;

            num2 = _iv.Encode(buffer, true);
            len += num2;

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Asn1Tag.Sequence, len);
            }

            return len;
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = 0;

            if (EncryptionParamSet != null)
            {
                len += EncryptionParamSet.Encode(buffer, true);
            }

            len += DigestParamSet.Encode(buffer, true);
            len += PublicKeyParamSet.Encode(buffer, true);

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Asn1Tag.Sequence, len);
            }

            return len;
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = 0;
            CheckTc(false);

            if (Parameters != null)
            {
                len += Parameters.Encode(buffer, true);
            }

            len += Algorithm.Encode(buffer, true);

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Asn1Tag.Sequence, len);
            }

            return len;
        }
Beispiel #27
0
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = 0;

            CheckAlg(false);

            if (Parameters != null)
            {
                len += Parameters.Encode(buffer, true);
            }

            len += Algorithm.Encode(buffer, true);

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Asn1Tag.Sequence, len);
            }

            return(len);
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            if (Value.Length < 1)
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidObjectIdException);
            }

            var len = 0;

            for (var i = Value.Length - 1; i >= 0; i--)
            {
                len += buffer.EncodeIdentifier(Value[i]);
            }

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Tag, len);
            }

            return len;
        }
Beispiel #29
0
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            int _aal = 0, len;

            // encode vals

            len   = vals.Encode(buffer, true);
            _aal += len;

            // encode type

            len   = type.Encode(buffer, true);
            _aal += len;

            if (explicitTagging)
            {
                _aal += buffer.EncodeTagAndLength(Asn1Tag.SEQUENCE, _aal);
            }

            return(_aal);
        }
Beispiel #30
0
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            int _aal = 0, len;

            // encode subjectPublicKey

            len   = subjectPublicKey.Encode(buffer, true);
            _aal += len;

            // encode algorithm

            len   = algorithm.Encode(buffer, true);
            _aal += len;

            if (explicitTagging)
            {
                _aal += buffer.EncodeTagAndLength(Asn1Tag.Sequence, _aal);
            }

            return(_aal);
        }
Beispiel #31
0
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            int _aal = 0, len;

            // encode encryptedParameters

            len   = encryptedParameters.Encode(buffer, true);
            _aal += len;

            // encode encryptedKey

            len   = encryptedKey.Encode(buffer, true);
            _aal += len;

            if (explicitTagging)
            {
                _aal += buffer.EncodeTagAndLength(Asn1Tag.Sequence, _aal);
            }

            return(_aal);
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            int num2;
            var len = 0;

            if (_extElem1 != null)
            {
                num2 = _extElem1.Encode(buffer, false);
                len += num2;
            }

            num2 = EncryptionParamSet.Encode(buffer, true);
            len += num2;

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Asn1Tag.Sequence, len);
            }

            return len;
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            int _aal = 0, len;

            // encode encryptionParamSet

            len   = encryptionParamSet.Encode(buffer, true);
            _aal += len;

            // encode iv

            len   = iv.Encode(buffer, true);
            _aal += len;

            if (explicitTagging)
            {
                _aal += buffer.EncodeTagAndLength(Asn1Tag.Sequence, _aal);
            }

            return(_aal);
        }
Beispiel #34
0
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            if (Value.Length < 1)
            {
                throw new Exception("Asn1InvalidObjectIdException");
            }

            var len = 0;

            for (var i = Value.Length - 1; i >= 0; i--)
            {
                len += buffer.EncodeIdentifier(Value[i]);
            }

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Tag, len);
            }

            return(len);
        }
Beispiel #35
0
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            int num2;
            var len = 0;

            if (_extElem1 != null)
            {
                num2 = _extElem1.Encode(buffer, false);
                len += num2;
            }

            num2 = EncryptionParamSet.Encode(buffer, true);
            len += num2;

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Asn1Tag.Sequence, len);
            }

            return(len);
        }
Beispiel #36
0
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = 0;

            if (Ukm != null)
            {
                if (Ukm.Length != 8)
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1ConsVioException, nameof(Ukm.Length), Ukm.Length);
                }

                len += Ukm.Encode(buffer, true);
            }

            len += EncryptionParamSet.Encode(buffer, true);

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Asn1Tag.Sequence, len);
            }

            return(len);
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = 0;

            if (Ukm != null)
            {
                if (Ukm.Length != 8)
                {
                    throw ExceptionUtility.CryptographicException(Resources.Asn1ConsVioException, "Ukm.Length", Ukm.Length);
                }

                len += Ukm.Encode(buffer, true);
            }

            len += EncryptionParamSet.Encode(buffer, true);

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Asn1Tag.Sequence, len);
            }

            return len;
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = 0;

            try
            {
                var bytes = Encoding.UTF8.GetBytes(Value);
                len = bytes.Length;
                buffer.Copy(bytes);
            }
            catch (IOException exception)
            {
                Console.Out.WriteLine("This JVM does not support UTF-8 encoding");
                Asn1Util.WriteStackTrace(exception, Console.Error);
            }

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Tag, len);
            }

            return len;
        }
Beispiel #39
0
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = 0;

            if (EncryptionParamSet != null)
            {
                len += EncryptionParamSet.Encode(buffer, true);
            }

            if (DigestParamSet != null)
            {
                len += DigestParamSet.Encode(buffer, true);
            }

            len += PublicKeyParamSet.Encode(buffer, true);

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Asn1Tag.Sequence, len);
            }

            return(len);
        }
        protected virtual int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging, Asn1Tag tag)
        {
            var length = Value.Length;
            buffer.Copy(Value);

            if (explicitTagging)
            {
                length += buffer.EncodeTagAndLength(tag, length);
            }

            return length;
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var length = Value.Length;

            for (var i = length - 1; i >= 0; --i)
            {
                var num3 = Value[i];
                var num = num3 % 0x100;
                var num2 = num3 / 0x100;

                buffer.Copy((byte)num);
                buffer.Copy((byte)num2);
            }

            length *= 2;

            if (explicitTagging)
            {
                length += buffer.EncodeTagAndLength(Tag, length);
            }

            return length;
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            if (((Value.Length < 2) || (Value[0] > 2)) || ((Value[0] != 2) && (Value[1] > 0x27)))
            {
                throw ExceptionUtility.CryptographicException(Resources.Asn1InvalidObjectIdException);
            }

            var len = 0;

            for (var i = Value.Length - 1; i >= 1; i--)
            {
                len += buffer.EncodeIdentifier((i == 1) ? ((Value[0] * 40) + Value[1]) : Value[i]);
            }

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Tag, len);
            }

            return len;
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            if (Value == null)
            {
                Value = new byte[0];
            }

            var length = Value.Length;

            if (length != 0)
            {
                buffer.Copy(Value);
            }

            if (explicitTagging)
            {
                length += buffer.EncodeTagAndLength(Tag, length);
            }

            return length;
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var length = _value.Length;

            for (var i = length - 1; i >= 0; i--)
            {
                var num3 = _value[i];

                for (var j = 0; j < 4; j++)
                {
                    var num = num3 % 0x100;
                    num3 /= 0x100;
                    buffer.Copy((byte)num);
                }
            }

            length *= 4;

            if (explicitTagging)
            {
                length += buffer.EncodeTagAndLength(Tag, length);
            }

            return length;
        }
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            int _aal = 0, len;

             // encode vals

             len = vals.Encode (buffer, true);
             _aal += len;

             // encode type

             len = type.Encode (buffer, true);
             _aal += len;

             if (explicitTagging) {
            _aal += buffer.EncodeTagAndLength (Asn1Tag.SEQUENCE, _aal);
             }

             return (_aal);
        }
Beispiel #46
0
        public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging)
        {
            var len = 0;

            if (double.IsNegativeInfinity(Value))
            {
                len = buffer.EncodeIntValue(MinusInfinity);
            }
            else if (double.IsPositiveInfinity(Value))
            {
                len = buffer.EncodeIntValue(PlusInfinity);
            }

            else if (Value != 0.0)
            {
                var num2 = BitConverter.DoubleToInt64Bits(Value);
                var num3 = ((num2 >> RealIso6093Mask) == 0L) ? 1 : -1;
                var num4 = ((int)((num2 >> 0x34) & 0x7ffL)) - 0x433;
                var w = (num4 == 0) ? ((num2 & 0xfffffffffffffL) << 1) : ((num2 & 0xfffffffffffffL) | 0x10000000000000L);

                if (w != 0L)
                {
                    var bits = TrailingZerosCnt(w);
                    w = Asn1Util.UrShift(w, bits);
                    num4 += bits;
                }

                len += buffer.EncodeIntValue(w);

                var num7 = buffer.EncodeIntValue(num4);
                len += num7;

                var num8 = RealBinary;

                if (num3 == -1)
                {
                    num8 |= PlusInfinity;
                }

                switch (num7)
                {
                    case RealExplen2:
                        break;

                    case RealExplen3:
                        num8 |= 1;
                        break;

                    case RealExplenLong:
                        num8 |= 2;
                        break;

                    default:
                        num8 |= 3;
                        len += buffer.EncodeIntValue(num7);
                        break;
                }

                buffer.Copy((byte)num8);
                len++;
            }

            if (explicitTagging)
            {
                len += buffer.EncodeTagAndLength(Tag, len);
            }

            return len;
        }