Extra Systems

CYPHERNET

key loading procedure load_rsa_keys


RSA encryption keys are stored on disk in packed form, and after reading (for further use) are unpacked element by element using the unpack_value procedure.

typedef struct rsa_key_item
{
	unsigned char exponent[VALUE_LENTH];
	unsigned char modulus[VALUE_LENTH];
} RSAKEYITEM;

typedef struct rsa_key_packed_item
{
	unsigned char exponent[PACKED_VALUE_LENTH];
	unsigned char modulus[PACKED_VALUE_LENTH];
} RSAKEYPACKEDITEM;

RSAKEYITEM encrypt_rsa_key, decrypt_rsa_key;

int load_rsa_keys(char *encrypt_rsa_key_file, char *decrypt_rsa_key_file)
{
	int file_handle;
	RSAKEYPACKEDITEM packed_key_item;
	if((file_handle = open(encrypt_rsa_key_file, O_RDONLY)) == -1) return 0;
	read(file_handle, &packed_key_item, sizeof(packed_key_item));
	close(file_handle);
	unpack_value(packed_key_item.exponent, encrypt_rsa_key.exponent);
	unpack_value(packed_key_item.modulus, encrypt_rsa_key.modulus);
	if((file_handle = open(decrypt_rsa_key_file, O_RDONLY)) == -1) return 0;
	read(file_handle, &packed_key_item, sizeof(packed_key_item));
	close(file_handle);
	unpack_value(packed_key_item.exponent, decrypt_rsa_key.exponent);
	unpack_value(packed_key_item.modulus, decrypt_rsa_key.modulus);
	return 1;
}

The parameters of this procedure are the names of the public (communication partner) and private (own) RSA key files.

The content of this page is also available in French, German, Ukrainian and Russian.


© Extra Systems, 2024 Extra Web Top