private SubjectPublicKeyInfo EncodePublicKey(Gost_R3410_KeyExchangeParams 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 = CreatePublicKeyParams(); publicKeyParams.PublicKeyParamSet = new Asn1ObjectIdentifier(OidValue.FromString(transportParameters.PublicKeyParamSet)); publicKeyParams.DigestParamSet = new Asn1ObjectIdentifier(OidValue.FromString(transportParameters.DigestParamSet)); publicKeyParams.EncryptionParamSet = Gost_28147_89_ParamSet.FromString(transportParameters.EncryptionParamSet); asnEncoder.Reset(); publicKeyParams.Encode(asnEncoder); var publicKeyAlgOid = new Asn1ObjectIdentifier(KeyAlgorithm); publicKeyInfo.Algorithm = new AlgorithmIdentifier(publicKeyAlgOid, new Asn1OpenType(asnEncoder.MsgCopy)); return(publicKeyInfo); }
/// <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); }
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 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; }