public override int Encode(Asn1BerEncodeBuffer buffer, bool explicitTagging) { int _aal = 0, len; switch (ChoiceId) { // encode null_ case _NULL_: NULLParams null_ = (NULLParams)GetElement(); len = null_.Encode(buffer, true); _aal += len; break; // encode params_ case _PARAMS_: GostR3410_2012_PublicKeyParameters params_ = (GostR3410_2012_PublicKeyParameters)GetElement(); len = params_.Encode(buffer, true); _aal += len; break; default: throw new Exception("Asn1InvalidChoiceOptionException()"); } return(_aal); }
/// <summary> /// Упаковка открытого ключа ГОСТ 34.10-2012 512 и его параметров в Asn1c структуру. /// </summary> /// /// <param name="pub">Открытый ключ.</param> /// /// <returns>Asn1c структура <c>SubjectPublicKeyInfo</c> открытого /// ключа.</returns> private static SubjectPublicKeyInfo PackPublicKeyInfo2012_512( Gost3410CspObject pub) { SubjectPublicKeyInfo spki = new SubjectPublicKeyInfo(); Asn1BerEncodeBuffer buffer = new Asn1BerEncodeBuffer(); Asn1OctetString publicKey = new Asn1OctetString(pub._publicKey); publicKey.Encode(buffer); byte[] octetString = buffer.MsgCopy; spki.subjectPublicKey = new Asn1BitString( octetString.Length * 8, octetString); GostR3410_2012_PublicKeyParameters par = new GostR3410_2012_PublicKeyParameters(); par.publicKeyParamSet = fromString(pub._publicKeyParamSet); par.digestParamSet = fromString(pub._digestParamSet); par.encryptionParamSet = CreateGost28147_89_ParamSet( pub._encryptionParamSet); buffer.Reset(); par.Encode(buffer); spki.algorithm = new AlgorithmIdentifier( fromString(GostConstants.OID_CP_GOST_R3410_12_512), new Asn1OpenType(buffer.MsgCopy)); return(spki); }