Skip to content

Instantly share code, notes, and snippets.

public static List<SecretKeyRequestModel> createEphSessionKeys(List<Certificate> recipientCertificate) throws KomandorException {
List<SecretKeyRequestModel> result = new ArrayList<>();
try {
for (Certificate certificate : recipientCertificate) {
// 1. Сертификат получателя.
//получаем параметры публичного ключа получателя. На его основании создадим ключ шифрования
X509Certificate recipientCert = decodeBase64Certificate(certificate.getBase64());
PublicKey recipientPubicKey = recipientCert.getPublicKey();
String recipientPubicKeyAlgorithm = recipientPubicKey.getAlgorithm();
public static List<SecretKeyRequestModel> createEphemeralSessionKeys(List<Certificate> recipientCertificate) throws KomandorException {
List<SecretKeyRequestModel> result = new ArrayList<>();
try {
Log.i(LOG_TAG, "Encrypt Session ephemeral key");
for (Certificate certificate : recipientCertificate) {
//генерируем симметричный ключ шифрования сообщений
final KeyGenerator keyGen = KeyGenerator.getInstance(CIPHER_ALG, PROVIDER);
final SecretKey symmetricKey = keyGen.generateKey();
char * cppImportSessionKeyEphem(const char * containerName, const char * containerPin, const char * sessionKey) {
HCRYPTPROV hProv = 0;
bool isPinOk = false;
HCRYPTKEY hResKey = 0;
size_t sessionDataSize = 0;
unsigned char * sessionData = NULL;
BYTE *pData = NULL;
DWORD dwEphemKeyBlobLen= 0;
BYTE *pbEphemKeyBlob = NULL;
HCRYPTKEY hAgreeKey = 0;
SessionKeyData * cppExportSessionKeyEphem(const char *keyId, const char * cert) {
//
SessionKeyData * keyData = NULL;
ProvKeyInfo pkInfo = ProvKeyInfoFromB64(keyId);
HCRYPTPROV hCryptProv = 0;
size_t certDataSize = 0;
unsigned char * certData = NULL;
HCRYPTKEY hCertPubKey = 0;
BYTE *pbBlob = NULL;
DWORD dwBlobLen = 0;
2019-08-13 12:39:40.571 23598-24351/app.komandor.messenger E/ERROR: java.lang.IllegalArgumentException: MSCAPI ERROR: 0x8009000a
2019-08-13 12:39:40.572 23598-24351/app.komandor.messenger W/System.err: app.komandor.messenger.utils.KomandorException: java.lang.IllegalArgumentException: MSCAPI ERROR: 0x8009000a
2019-08-13 12:39:40.573 23598-24351/app.komandor.messenger W/System.err: at app.komandor.messenger.utils.CryptoUtils.sign(CryptoUtils.java:152)
2019-08-13 12:39:40.574 23598-24351/app.komandor.messenger W/System.err: at app.komandor.messenger.data.temporary.CryptoStorage.sign(CryptoStorage.java:64)
2019-08-13 12:39:40.575 23598-24351/app.komandor.messenger W/System.err: at app.komandor.messenger.data.temporary.CryptoStorage.signSelectedCertificate(CryptoStorage.java:149)
2019-08-13 12:39:40.576 23598-24351/app.komandor.messenger W/System.err: at app.komandor.messenger.ui.auth.cert_validation.CertValidationViewModel.lambda$validateCertificate$1$CertValidationViewModel(CertValidationViewMod
@ReFLeXive007
ReFLeXive007 / decrypt.java
Created August 7, 2019 19:11
Расшифровка
public static DecryptedSessionKey decryptSessionKey(PrivateKey pk, EncryptedSessionKey encryptedSessionKey) throws KomandorException {
SecretKey key_ = null;
byte[] iv = null;
try {
int sizeLength = 4;
byte[] bKey = Base64.decode(encryptedSessionKey.getEncryptedKey(), Base64.NO_WRAP);
byte[] bBlobLength = SystemUtils.reverseByteArray(Arrays.copyOfRange(bKey, 0, sizeLength));
int blobLength = ByteBuffer.wrap(bBlobLength).getInt();
@ReFLeXive007
ReFLeXive007 / sessionKeys.java
Created August 7, 2019 19:09
Сессионные ключи
public static List<SecretKeyRequestModel> createSessionKeys(PrivateKey pk, List<Certificate> certificates) throws KomandorException {
List<SecretKeyRequestModel> keys = new ArrayList<>();
try {
/* Генерирование симметричного ключа с параметрами шифрования из контрольной панели*/
final KeyGenerator keyGen = KeyGenerator.getInstance(CIPHER_ALG, JCSP.PROVIDER_NAME);
final SecretKey simm = keyGen.generateKey();
final byte[] iv = new byte[RND_LENGTH];
final SecureRandom random = SecureRandom.getInstance(RANDOM_ALG, JCSP.PROVIDER_NAME);
random.nextBytes(iv);