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); }
public override void Decode (Asn1BerDecodeBuffer buffer, bool explicitTagging, int implicitLength) { int llen = implicitLength; // decode CHOICE Asn1Tag tag = new Asn1Tag(); buffer.Mark(); int len = buffer.DecodeTagAndLength(tag); if (tag.Equals(Asn1Tag.Universal, Asn1Tag.PRIM, 5)) { buffer.Reset(); NULLParams null_ = new NULLParams(); SetElement(_NULL_, null_); Element.Decode(buffer, true, len); } else if (tag.Equals(Asn1Tag.Universal, Asn1Tag.CONS, 16)) { buffer.Reset(); GostR3410_2012_PublicKeyParameters params_ = new GostR3410_2012_PublicKeyParameters(); SetElement(_PARAMS_, params_); Element.Decode(buffer, true, len); } else { throw new Exception("Asn1InvalidChoiceOptionException (buffer, tag)"); } }
/// <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); }
/// <summary> /// Разбор декодированной ASN1c структуры ГОСТ 34.10-2012 <c>SubjectPublicKeyInfo</c>. /// </summary> /// /// <param name="spki">ASN1c структура <c>SubjectPublicKeyInfo</c>. /// </param> /// /// <returns>Параметры открытого ключа.</returns> /// <argnull name="spki" /> /// <exception cref="ArgumentException">Если вложенная структура /// не приводится к <c>GostR3410_2001_PublicKeyParameters</c> /// </exception> private static Gost3410CspObject UnpackPublicKeyInfo2012( SubjectPublicKeyInfo spki) { if (spki == null) { throw new ArgumentNullException("spki"); } Asn1Choice choice = spki.algorithm.parameters as Asn1Choice; if (choice == null) { throw new ArgumentException( "spki.algorithm.parameters"); } GostR3410_2012_PublicKeyParameters publicKeyParameters = choice.GetElement() as GostR3410_2012_PublicKeyParameters; if (publicKeyParameters == null) { throw new ArgumentException( "spki.algorithm.parameters.element"); } byte[] bitString = spki.subjectPublicKey.Value; Asn1BerDecodeBuffer buffer = new Asn1BerDecodeBuffer(bitString); Asn1OctetString publicKey = new Asn1OctetString(); publicKey.Decode(buffer); Gost3410CspObject ret = new Gost3410CspObject(); ret._publicKeyParamSet = toString( publicKeyParameters.publicKeyParamSet); ret._digestParamSet = toString( publicKeyParameters.digestParamSet); ret._encryptionParamSet = toString( publicKeyParameters.encryptionParamSet); ret._publicKey = publicKey.Value; ret._privateKey = null; return(ret); }
public void Set_params_(GostR3410_2012_PublicKeyParameters value) { SetElement(_PARAMS_, value); }