Git Product home page Git Product logo

netwinapicms's Introduction

NetWinapiCms

.NET 7 doesn't support non-Microsoft hash algorithms, and, may be, assymetric algorithms too. This can be a problem for Russia, Kazakhstan and other countries, where national cryptographic algorithms are obligatory.

In the older .NET Framework that stuff works fine, but the .NET Team, I guess, hasn't had enough motivation to fix it in new version of the framework. See dotnet/runtime#26053 for details.

So, there are examples of using WinAPI functions as a workaround +for CMS signing and verifying.

Usage

For signing data use the following code snippet:

var certificate = new X509Certificate(...);
var data = Encoding.UTF8.GetBytes("Test");
Oid digestOid;
if (certificate.PublicKey.Oid.Value == GostOids.id_tc26_gost3410_12_256.Value)
	digestOid = GostOids.id_tc26_gost3411_12_256;
else if (certificate.PublicKey.Oid.Value == GostOids.id_tc26_gost3410_12_512.Value)
	digestOid = GostOids.id_tc26_gost3411_12_512;
else
	digestOid = OiwOids.id_sha1;
	
var signedCms = CmsHelper.Sign(data, true, certificate, digestOid, true, "12345678");

For verifiying the previously signed data use the following code:

CmsHelper.Verify(signedCms, true, data, true, X509RevocationMode.Online, X509RevocationFlag.ExcludeRoot);

License

This repo is licensed under the MIT license.

netwinapicms's People

Contributors

larinlive avatar

Stargazers

 avatar  avatar Stanislav avatar  avatar  avatar Roman Tkachev avatar Nick Martyshchenko avatar  avatar vinogradov avatar BlueSharkPartners avatar Daniel Neslukhovskiy avatar  avatar Ilya avatar Artem Osta avatar Ivan Modin avatar

Watchers

Max avatar Roman Tkachev avatar vinogradov avatar  avatar  avatar

netwinapicms's Issues

Ошибка "Неизвестный криптографический алгоритм"

Установлен Крипто Про 4,0.

При попытке выполнить подпись получаю ошибку "Неизвестный криптографический алгоритм.". Ошибка происходит при вызове функции CryptMsgOpenToEncode.

Предполагаю, что неправильно устанавливается oid в строчке:
Encoding.ASCII.GetBytes(pin, new Span<byte>(digestOidRaw, digestOidLength));

Но даже с учетом исправления этой ошибки, все равно получаю "Неизвестный криптографический алгоритм".

При попытке выполнить проверку подписи получаю ошибку "Параметр задан неверно." при вызове функции CryptMsgControl.

Добавление метки времени

Подскажите, пожалуйста, а как реализовать добавление TimeStamp, дабы установить метку времени в подпись?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.