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, ObjectIdentifierTypeCode, parsedLen, false)) { throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount); } EncryptionParamSet = new Gost2814789ParamSet(); EncryptionParamSet.Decode(buffer, true, parsedLen.Value); if (context.MatchElemTag(0x80, 0x20, EocTypeCode, parsedLen, true)) { EphemeralPublicKey = new SubjectPublicKeyInfo(); EphemeralPublicKey.Decode(buffer, false, parsedLen.Value); } if (!context.MatchElemTag(0, 0, OctetStringTypeCode, parsedLen, false)) { throw ExceptionUtility.CryptographicException(Resources.Asn1MissingRequiredException, buffer.ByteCount); } Ukm = new Asn1OctetString(); Ukm.Decode(buffer, true, parsedLen.Value); if (Ukm.Length != 8) { throw ExceptionUtility.CryptographicException(Resources.Asn1ConsVioException, "Ukm.Length", Ukm.Length); } }
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; }
private void Init() { EncryptionParamSet = null; EphemeralPublicKey = null; Ukm = null; }