Пример #1
0
int main(void)
{
    char tarck2[18]="\x33\x33\x33\x33\x33\x33\x44\x54\x56\xD0\x01\x25\x25\x00\x08\x89\x59\x60";
    char out[512];
    char unout[512];
    char desout[128];
    char checkout[10];
    int len=0;
    memset(out,0,512);
    memset(unout,0,128);
    memset(desout,0,128);
    memset(checkout,0,10);
    /*DebugBuff("Tarck2",tarck2,18);
    EnTarck2(tarck2,18,out,"1234567887654321");
    DebugBuff("EnTarck2",out,50);
    UnTarck2(out,50,unout,"1234567887654321");
    DebugBuff("UnTarck2",unout,50);*/
    /*EnANSIX98("1234567887654321","123456789012345678",18,"123456789012",12,out);
    DebugBuff("EnANSIX98",out,8);
    UnANSIX98("1234567887654321","123456789012345678",18,unout,&len,out);
    DebugBuff("UnANSIX98",unout,len);*/

    //GetTMK("31323334353637383837363534333231",out,unout);
    //GetPIK(unout,out,desout,checkout);
    //GetTRK(unout,out,desout,checkout);
    //UnTRK("31313131313131313131313131313131","1A9C9B7A055CA95E750F45D826CE4D00",out,checkout);

    RSAPublicEncrypt("31323334353637383837363534333231",out);
    RSAPrivateDecrypte(out,unout);
    printf("%s\r\n\r\n\r\n%s",out,unout);
}
Пример #2
0
SENSECRYPTDLL_API int S4RSAPublicEncrypt(
			unsigned char *output,
			unsigned char *input,
			unsigned int inputLen
		  )
{
	unsigned int outLen;
	char* outbase64;
	int ret = RSAPublicEncrypt(output, &outLen, input, inputLen, &publicKey);
	outbase64 = base64_encode(output, outLen);
	memcpy(output, outbase64, strlen(outbase64));
	free(outbase64);

	return ret;
}
Пример #3
0
static int rsaref_public_encrypt(int len, const unsigned char *from, unsigned char *to,
	     RSA *rsa, int padding)
	{
	int outlen= -1;
	int i;
	R_RSA_PUBLIC_KEY RSAkey;
	R_RANDOM_STRUCT rnd;
	unsigned char buf[16];

	if (padding != RSA_PKCS1_PADDING && padding != RSA_SSLV23_PADDING) 
		{
		RSAREFerr(RSAREF_F_RSAREF_PUBLIC_ENCRYPT, RSA_R_UNKNOWN_PADDING_TYPE);
		goto err;
		}
	
	R_RandomInit(&rnd);
	R_GetRandomBytesNeeded((unsigned int *)&i,&rnd);
	while (i > 0)
		{
		if (RAND_bytes(buf,16) <= 0)
			goto err;
		R_RandomUpdate(&rnd,buf,(unsigned int)((i>16)?16:i));
		i-=16;
		}

	if (!RSAref_Public_eay2ref(rsa,&RSAkey))
		goto err;
	if ((i=RSAPublicEncrypt(to,(unsigned int *)&outlen,(unsigned char *)from,len,&RSAkey,&rnd)) != 0)
		{
		RSAREFerr(RSAREF_F_RSAREF_PUBLIC_ENCRYPT,i);
		outlen= -1;
		goto err;
		}
err:
	memset(&RSAkey,0,sizeof(RSAkey));
	R_RandomFinal(&rnd);
	memset(&rnd,0,sizeof(rnd));
	return(outlen);
	}
Пример #4
0
NEINT32 ne_RSAPublicEncrypt(NEINT8 *outbuf, NEINT32 *outlen, NEINT8 *inbuf, NEINT32 inlen,RSA_HANDLE h_rsa)
{
	return RSAPublicEncrypt(outbuf, outlen, inbuf, inlen, &(h_rsa->publicKey) , &(h_rsa->randomStruct)) ;
}