/// <summary> /// Экспортирует (шифрует) секретный ключ. /// </summary> /// <param name="prov">Шифруемый ключ.</param> /// <param name="method">Алгоритм экспорта ключа.</param> /// <returns>Зашифрованный симметричный ключ</returns> public override byte[] Wrap(Gost28147 prov, GostKeyWrapMethod method) { SafeKeyHandle hSimmKey = ((Gost28147CryptoServiceProvider)prov).SafeKeyHandle; int calg = GostConstants.CALG_SIMPLE_EXPORT; if (method == GostKeyWrapMethod.CryptoProKeyWrap) { calg = GostConstants.CALG_PRO_EXPORT; } else if (method == GostKeyWrapMethod.CryptoPro12KeyWrap) { calg = GostConstants.CALG_PRO12_EXPORT; } else if (method != GostKeyWrapMethod.GostKeyWrap) { throw new ArgumentOutOfRangeException("method"); } byte[] ret = null; // Сохраняем состояние algid GOST12147 using (SafeKeyHandle hExpKey = CapiHelper.DuplicateKey( SafeKeyHandle.DangerousGetHandle(), SafeProvHandle)) { CapiHelper.SetKeyParameter(hExpKey, GostConstants.KP_ALGID, calg); CapiHelper.SetKeyParameter(hExpKey, GostConstants.KP_IV, IV); GostWrappedKeyObject wrappedKey = new GostWrappedKeyObject(); CapiHelper.ExportSessionWrapedKey(hSimmKey, hExpKey, wrappedKey); ret = wrappedKey.GetXmlWrappedKey(); } return(ret); }
/// <summary> /// Экспортирует (шифрует) секретный ключ. /// </summary> /// <param name="prov">Шифруемый ключ.</param> /// <param name="method">Алгоритм экспорта ключа.</param> /// <returns>Зашифрованный симметричный ключ</returns> public override byte[] Wrap(Gost28147 prov, GostKeyWrapMethod method) { throw new NotImplementedException(); //SafeKeyHandle hSimmKey = ((Gost28147CryptoServiceProvider)prov).SafeKeyHandle; //int calg = GostConstants.CALG_SIMPLE_EXPORT; //if (method == GostKeyWrapMethod.CryptoProKeyWrap) // calg = GostConstants.CALG_PRO_EXPORT; //else if (method == GostKeyWrapMethod.CryptoPro12KeyWrap) // calg = GostConstants.CALG_PRO12_EXPORT; //else if (method != GostKeyWrapMethod.GostKeyWrap) // throw new ArgumentOutOfRangeException("method"); //byte[] ret = null; //// Сохраняем состояние algid GOST12147 //using (SafeKeyHandle hExpKey = CapiHelper.DuplicateKey(SafeKeyHandle.DangerousGetHandle()) //{ // CapiHelper.SetKeyParameter(hExpKey, GostConstants.KP_ALGID, calg); // CapiHelper.SetKeyParameter(hExpKey, GostConstants.KP_IV, IV); // GostWrappedKeyObject wrappedKey = new GostWrappedKeyObject(); // CapiHelper.ExportSessionWrapedKey(hSimmKey, // hExpKey, wrappedKey); // ret = wrappedKey.GetXmlWrappedKey(); //} //return ret; }
/// <summary> /// Зашифрование (экспорт) симметричного ключа. /// </summary> /// /// <remarks><para>Формат зашифрованного ключа зависит от метода /// зашифрования; для <see cref="GostKeyWrapMethod.GostKeyWrap"/> и /// <see cref="GostKeyWrapMethod.CryptoProKeyWrap"/> /// формат зашифрованного ключа определяется функцией /// <see cref="GostWrappedKey.GetXmlWrappedKey"/>.</para> /// /// <para>При зашифровании ключа используется синхропосылка /// заданная <see cref="SymmetricAlgorithm.IV"/></para> /// </remarks> /// /// <param name="alg">Объект класса <see cref="SymmetricAlgorithm"/>, /// содержащий симметричный ключ.</param> /// <param name="method">Алгоритм экспорта ключа.</param> /// /// <returns>Зашифрованный симметричный ключ.</returns> /// /// <seealso cref="GostWrappedKey"/> /// <seealso cref="GostSharedSecretCryptoServiceProvider.Unwrap"/> public override byte[] Wrap(SymmetricAlgorithm alg, GostKeyWrapMethod method) { Gost28147 gost = alg as Gost28147; if (gost == null) { throw new ArgumentException(nameof(alg)); } Gost28147CryptoServiceProvider prov = gost as Gost28147CryptoServiceProvider; if (prov == null) { using (Gost28147CryptoServiceProvider p = new Gost28147CryptoServiceProvider()) { return(p.Wrap(prov, method)); } } return(Wrap(prov, method)); }
public override byte[] Wrap(Gost28147 keyExchangeAlgorithm, GostKeyWrapMethod method) { throw null; }
/// <summary> /// Экспортирует (шифрует) секретный ключ. /// </summary> /// <param name="prov">Шифруемый ключ.</param> /// <param name="method">Алгоритм экспорта ключа.</param> /// <returns>Зашифрованный симметричный ключ</returns> public abstract byte[] Wrap(Gost28147 prov, GostKeyWrapMethod method);