Extra Systems

CYPHERNET

RSA key conversion procedure from text to binary format rsa_key_bin


The rsa_key_bin procedure reads RSA keys in text form (generated by the keygen procedure) from disk and writes them in binary form. This procedure is called from the scripts that form the Extra Systems Cypher Net encryption software package. The name of the file to be processed is passed to this program as a command line parameter. As can be seen from the text below, the utility simply adds the ".bin" extension to the name to form the output file.

#include "cyphernet.h"

int main (int argc, char *argv[])
{
	int file_handle;
	char str_buf[4096];
	RSAKEYITEM key_item;
	RSAKEYPACKEDITEM packed_key_item;
	if((file_handle = open(argv[1], O_RDONLY)) == -1) return 1;
	read(file_handle, str_buf, 4096);
	close(file_handle);
	str_to_value(strtok(str_buf, " "), key_item.modulus);
	str_to_value(strtok(NULL, " "), key_item.exponent);
	pack_value(key_item.exponent, packed_key_item.exponent);
	pack_value(key_item.modulus, packed_key_item.modulus);
	strcpy(str_buf, argv[1]);
	strcat(str_buf, ".bin");
	file_handle = creat(str_buf, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
	write(file_handle, &packed_key_item, sizeof(packed_key_item));
	close(file_handle);
	return 0;
}

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


© Extra Systems, 2024 Extra Web Top