/// <summary> /// Расшифровать информацию о ключе. /// </summary> public byte[] Encode() { byte[] data; var keyWrap = new Gost_28147_89_KeyWrap(); try { keyWrap.EncryptedKey = new Gost_28147_89_EncryptedKey { EncryptedKey = new Gost_28147_89_Key(EncryptedKey), MacKey = new Gost_28147_89_Mac(Mac) }; keyWrap.EncryptedParams = new Gost_28147_89_KeyWrapParams { EncryptionParamSet = Gost_28147_89_ParamSet.FromString(EncryptionParamSet), Ukm = new Asn1OctetString(Ukm) }; var asnEncoder = new Asn1BerEncodeBuffer(); keyWrap.Encode(asnEncoder); data = asnEncoder.MsgCopy; } catch (Exception exception) { throw ExceptionUtility.CryptographicException(exception, Resources.Asn1DecodeError, nameof(Gost_28147_89_KeyWrap)); } return(data); }
/// <summary> /// Зашифровать информацию о ключе. /// </summary> public void Decode(byte[] data) { if (data == null) { throw ExceptionUtility.ArgumentNull(nameof(data)); } try { var asnDecoder = new Asn1BerDecodeBuffer(data); var keyWrap = new Gost_28147_89_KeyWrap(); keyWrap.Decode(asnDecoder); EncryptionParamSet = keyWrap.EncryptedParams.EncryptionParamSet.Oid.Value; EncryptedKey = keyWrap.EncryptedKey.EncryptedKey.Value; Mac = keyWrap.EncryptedKey.MacKey.Value; Ukm = keyWrap.EncryptedParams.Ukm.Value; } catch (Exception exception) { throw ExceptionUtility.CryptographicException(exception, Resources.Asn1DecodeError, nameof(Gost_28147_89_KeyWrap)); } }