Exemplo n.º 1
0
        public byte[] Encode()
        {
            byte[] data;

            var keyWrap = new GostR3410KeyWrap();

            try
            {
                keyWrap.EncryptedKey = new Gost2814789EncryptedKey
                {
                    EncryptedKey = new Gost2814789Key(EncryptedKey),
                    MacKey       = new Gost2814789Mac(Mac)
                };

                keyWrap.EncryptedParameters = new Gost2814789KeyWrapParameters
                {
                    EncryptionParamSet = CreateEncryptionParamSet(EncryptionParamSet),
                    Ukm = new Asn1OctetString(Ukm)
                };

                var asnEncoder = new Asn1BerEncodeBuffer();
                keyWrap.Encode(asnEncoder);
                data = asnEncoder.MsgCopy;
            }
            catch (Exception exception)
            {
                throw ExceptionUtility.CryptographicException(exception, Resources.Asn1DecodeError, typeof(GostR3410KeyWrap).FullName);
            }

            return(data);
        }
Exemplo n.º 2
0
        public void Decode(byte[] data)
        {
            if (data == null)
            {
                throw ExceptionUtility.ArgumentNull("data");
            }

            try
            {
                var asnDecoder = new Asn1BerDecodeBuffer(data);
                var keyWrap    = new GostR3410KeyWrap();
                keyWrap.Decode(asnDecoder);

                EncryptionParamSet = Asn1ObjectIdentifier.ToOidString(keyWrap.EncryptedParameters.EncryptionParamSet);
                EncryptedKey       = keyWrap.EncryptedKey.EncryptedKey.Value;
                Mac = keyWrap.EncryptedKey.MacKey.Value;
                Ukm = keyWrap.EncryptedParameters.Ukm.Value;
            }
            catch (Exception exception)
            {
                throw ExceptionUtility.CryptographicException(exception, Resources.Asn1DecodeError, typeof(GostR3410KeyWrap).FullName);
            }
        }