public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength) { var elemLength = explicitTagging ? MatchTag(buffer, Asn1Tag.Sequence) : implicitLength; Init(); var context = new Asn1BerDecodeContext(buffer, elemLength); var parsedLen = new IntHolder(); if (!context.MatchElemTag(0, 0, 6, parsedLen, false)) { throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount); } Algorithm = new Asn1ObjectIdentifier(); Algorithm.Decode(buffer, true, parsedLen.Value); if (!context.Expired()) { Parameters = new Asn1OpenType(); Parameters.Decode(buffer, true, 0); } CheckTc(true); }
public override void Decode(Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength) { var elemLength = explicitTagging ? MatchTag(buffer, Asn1Tag.Sequence) : implicitLength; Init(); var context = new Asn1BerDecodeContext(buffer, elemLength); var parsedLen = new IntHolder(); if (!context.MatchElemTag(0, 0, 6, parsedLen, false)) { throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount); } _publicKeyParamSet = new Asn1ObjectIdentifier(); _publicKeyParamSet.Decode(buffer, true, parsedLen.Value); if (!context.MatchElemTag(0, 0, 6, parsedLen, false)) { throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount); } _digestParamSet = new Asn1ObjectIdentifier(); _digestParamSet.Decode(buffer, true, parsedLen.Value); if (context.MatchElemTag(0, 0, 6, parsedLen, false)) { _encryptionParamSet = new Gost2814789ParamSet(); _encryptionParamSet.Decode(buffer, true, parsedLen.Value); } }
public AlgorithmId(Asn1ObjectIdentifier id, Asn1Type type) { Id = id; Type = type; }
private void Init() { _publicKeyParamSet = null; _digestParamSet = null; _encryptionParamSet = null; }
private void Init() { Algorithm = null; Parameters = null; }
public AlgorithmIdentifier(Asn1ObjectIdentifier algorithm, Asn1OpenType parameters) { Algorithm = algorithm; Parameters = parameters; }
private static SubjectPublicKeyInfo EncodePublicKey(GostKeyExchangeParameters transportParameters) { var asnEncoder = new Asn1BerEncodeBuffer(); var publicKey = new Asn1OctetString(transportParameters.PublicKey); publicKey.Encode(asnEncoder); var publicKeyValue = asnEncoder.MsgCopy; var publicKeyInfo = new SubjectPublicKeyInfo { SubjectPublicKey = new Asn1BitString(publicKeyValue.Length * 8, publicKeyValue) }; var publicKeyParams = new GostR34102001PublicKeyParameters { PublicKeyParamSet = Asn1ObjectIdentifier.FromOidString(transportParameters.PublicKeyParamSet), DigestParamSet = Asn1ObjectIdentifier.FromOidString(transportParameters.DigestParamSet), EncryptionParamSet = CreateEncryptionParamSet(transportParameters.EncryptionParamSet) }; asnEncoder.Reset(); publicKeyParams.Encode(asnEncoder); var publicKeyAlgOid = new Asn1ObjectIdentifier(GostR34102001Constants.IdGostR34102001); publicKeyInfo.Algorithm = new AlgorithmIdentifier(publicKeyAlgOid, new Asn1OpenType(asnEncoder.MsgCopy)); return publicKeyInfo; }
public static Asn1ObjectIdentifier FromOidString(string value) { Asn1ObjectIdentifier identifier; if (value == null) { return null; } var num = 1; foreach (var ch in value) { if (ch == '.') { num++; } } var numArray = new int[num]; var num2 = 0; num = 0; while (num2 < value.Length) { var c = value[num2]; if (!char.IsDigit(c)) { throw ExceptionUtility.CryptographicException(Resources.Asn1EncodeErrorWithValue, typeof(Asn1ObjectIdentifier).FullName, value); } var num3 = 0; while (num2 < value.Length) { c = value[num2++]; if (c == '.') { break; } if (!char.IsDigit(c)) { throw ExceptionUtility.CryptographicException(Resources.Asn1EncodeErrorWithValue, typeof(Asn1ObjectIdentifier).FullName, value); } num3 = ((num3 * 10) + c) - 48; } numArray[num++] = num3; } try { identifier = new Asn1ObjectIdentifier(numArray); } catch (Exception exception) { throw ExceptionUtility.CryptographicException(exception, Resources.Asn1EncodeError, typeof(Asn1ObjectIdentifier).FullName); } return identifier; }
public static string ToOidString(Asn1ObjectIdentifier id) { if (id != null) { var builder = new StringBuilder(id.Value.Length * 10); foreach (var num in id.Value) { builder.Append("." + num); } return builder.ToString().Substring(1); } return null; }
public static Asn1ObjectIdentifier FromOidString(string value) { Asn1ObjectIdentifier identifier; if (value == null) { return(null); } var num = 1; foreach (var ch in value) { if (ch == '.') { num++; } } var numArray = new int[num]; var num2 = 0; num = 0; while (num2 < value.Length) { var c = value[num2]; if (!char.IsDigit(c)) { throw ExceptionUtility.CryptographicException(Resources.Asn1EncodeErrorWithValue, typeof(Asn1ObjectIdentifier).FullName, value); } var num3 = 0; while (num2 < value.Length) { c = value[num2++]; if (c == '.') { break; } if (!char.IsDigit(c)) { throw ExceptionUtility.CryptographicException(Resources.Asn1EncodeErrorWithValue, typeof(Asn1ObjectIdentifier).FullName, value); } num3 = ((num3 * 10) + c) - 48; } numArray[num++] = num3; } try { identifier = new Asn1ObjectIdentifier(numArray); } catch (Exception exception) { throw ExceptionUtility.CryptographicException(exception, Resources.Asn1EncodeError, typeof(Asn1ObjectIdentifier).FullName); } return(identifier); }
private void Init() { DigestParamSet = null; PublicKeyParamSet = null; EncryptionParamSet = null; }