C# Подписать текстовый документ.
Здравствуйте.
У меня задача найти сертификат в токене по какому то параметру который я могу увидеть в справочнике сертификатов.
Если через крипто про то я нахожу сертификат по понятному имени.
Не понимаю как мне найти сертификат через API на C#
в взял Пример - Standard.SignVerifyGOST34.10-2012-256
Дописал в нем код
List<CKA> valuesAsArray = new List<CKA>();
foreach (var v in Enum.GetValues(typeof(CKA)))
{
valuesAsArray.Add((CKA)v);
}
int i = 1;
foreach (var f in privateKeys)
{
Print(valuesAsArray, session, f, $"PRIVATE {i++}");
}
foreach (var f in publicKeys)
{
Print(valuesAsArray, session, f, $"PUBLIC {i++}");
}
public static void Print(List<CKA> valuesAsArray, Session session, ObjectHandle key, string iteration)
{
Console.WriteLine($"Begin {iteration}");
foreach (var v in valuesAsArray)
{
try
{
List<ObjectAttribute> keyValue = session.GetAttributeValue(key, new List<CKA> { v });
foreach (var o in keyValue)
{
switch (v)
{
case CKA.CKA_ISSUER:
case CKA.CKA_LABEL:
var s = o.GetValueAsString();
Console.WriteLine($"{v}={s}");
break;
case CKA.CKA_START_DATE:
case CKA.CKA_END_DATE:
var d = o.GetValueAsDateTime();
Console.WriteLine($"{v}={d}");
break;
default:
var b = o.GetValueAsByteArray();
Console.WriteLine($"{v}={System.Text.Encoding.UTF8.GetString(b)} -><- {Convert.ToBase64String(b)}");
break;
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Failed to get {v}={ex.Message}");
}
}
Console.WriteLine($"End {iteration}");
}
Запустил и он мне вообще практически никакой полезной информации не выдает. У меня никак не получается сопоставить данные сертификата с тем что я вижу в справочнике. Подскажите пожалуйста что делаю не так.
Begin PRIVATE 1
CKA_ID=????MP?? F9oT0h6NDL5NUO77Pjy+4uGbRfI=
Failed to get CKA_APPLICATION=Value of attribute CKA_APPLICATION could not be read
Failed to get CKA_VALUE=Value of attribute CKA_VALUE could not be read
Failed to get CKA_OBJECT_ID=Value of attribute CKA_OBJECT_ID could not be read
Failed to get CKA_CERTIFICATE_TYPE=Value of attribute CKA_CERTIFICATE_TYPE could not be read
Failed to get CKA_ISSUER=Value of attribute CKA_ISSUER could not be read
Failed to get CKA_SERIAL_NUMBER=Value of attribute CKA_SERIAL_NUMBER could not be read
Failed to get CKA_AC_ISSUER=Value of attribute CKA_AC_ISSUER could not be read
Failed to get CKA_OWNER=Value of attribute CKA_OWNER could not be read
Failed to get CKA_ATTR_TYPES=Value of attribute CKA_ATTR_TYPES could not be read
Failed to get CKA_TRUSTED=Value of attribute CKA_TRUSTED could not be read
Failed to get CKA_CERTIFICATE_CATEGORY=Value of attribute CKA_CERTIFICATE_CATEGORY could not be read
Failed to get CKA_JAVA_MIDP_SECURITY_DOMAIN=Value of attribute CKA_JAVA_MIDP_SECURITY_DOMAIN could not be read
Failed to get CKA_URL=Value of attribute CKA_URL could not be read
Failed to get CKA_HASH_OF_SUBJECT_PUBLIC_KEY=Value of attribute CKA_HASH_OF_SUBJECT_PUBLIC_KEY could not be read
Failed to get CKA_HASH_OF_ISSUER_PUBLIC_KEY=Value of attribute CKA_HASH_OF_ISSUER_PUBLIC_KEY could not be read
Failed to get CKA_CHECK_VALUE=Value of attribute CKA_CHECK_VALUE could not be read
Failed to get CKA_MODULUS=Value of attribute CKA_MODULUS could not be read
Failed to get CKA_MODULUS_BITS=Value of attribute CKA_MODULUS_BITS could not be read
Failed to get CKA_PUBLIC_EXPONENT=Value of attribute CKA_PUBLIC_EXPONENT could not be read
Failed to get CKA_PRIVATE_EXPONENT=Value of attribute CKA_PRIVATE_EXPONENT could not be read
Failed to get CKA_PRIME_1=Value of attribute CKA_PRIME_1 could not be read
Failed to get CKA_PRIME_2=Value of attribute CKA_PRIME_2 could not be read
Failed to get CKA_EXPONENT_1=Value of attribute CKA_EXPONENT_1 could not be read
Failed to get CKA_EXPONENT_2=Value of attribute CKA_EXPONENT_2 could not be read
Failed to get CKA_COEFFICIENT=Value of attribute CKA_COEFFICIENT could not be read
Failed to get CKA_PUBLIC_KEY_INFO=Value of attribute CKA_PUBLIC_KEY_INFO could not be read
Failed to get CKA_PRIME=Value of attribute CKA_PRIME could not be read
Failed to get CKA_SUBPRIME=Value of attribute CKA_SUBPRIME could not be read
Failed to get CKA_BASE=Value of attribute CKA_BASE could not be read
Failed to get CKA_PRIME_BITS=Value of attribute CKA_PRIME_BITS could not be read
Failed to get CKA_SUBPRIME_BITS=Value of attribute CKA_SUBPRIME_BITS could not be read
Failed to get CKA_VALUE_BITS=Value of attribute CKA_VALUE_BITS could not be read
Failed to get CKA_VALUE_LEN=Value of attribute CKA_VALUE_LEN could not be read