mirror of
https://github.com/openssl/openssl.git
synced 2024-12-14 04:24:23 +08:00
Implement encrypt/decrypt using RSA.
This commit is contained in:
parent
07e970c7e6
commit
8cd44e3630
@ -163,8 +163,8 @@ int MAIN(int argc, char **argv)
|
||||
hexdump = 1;
|
||||
else if(!strcmp(*argv, "-sign"))
|
||||
pkey_op = EVP_PKEY_OP_SIGN;
|
||||
else if(!strcmp(*argv, "-verify"))
|
||||
pkey_op = EVP_PKEY_OP_VERIFY;
|
||||
else if(!strcmp(*argv, "-verifyrecover"))
|
||||
pkey_op = EVP_PKEY_OP_VERIFYRECOVER;
|
||||
else if(!strcmp(*argv, "-rev"))
|
||||
rev = 1;
|
||||
else if(!strcmp(*argv, "-encrypt"))
|
||||
|
@ -125,6 +125,31 @@ static int pkey_rsa_verifyrecover(EVP_PKEY_CTX *ctx,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int pkey_rsa_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out, int *outlen,
|
||||
unsigned char *in, int inlen)
|
||||
{
|
||||
int ret;
|
||||
RSA_PKEY_CTX *rctx = ctx->data;
|
||||
ret = RSA_public_encrypt(inlen, in, out, ctx->pkey->pkey.rsa,
|
||||
rctx->pad_mode);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
*outlen = ret;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int pkey_rsa_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out, int *outlen,
|
||||
unsigned char *in, int inlen)
|
||||
{
|
||||
int ret;
|
||||
RSA_PKEY_CTX *rctx = ctx->data;
|
||||
ret = RSA_private_decrypt(inlen, in, out, ctx->pkey->pkey.rsa,
|
||||
rctx->pad_mode);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
*outlen = ret;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const EVP_PKEY_METHOD rsa_pkey_meth =
|
||||
{
|
||||
@ -143,6 +168,18 @@ const EVP_PKEY_METHOD rsa_pkey_meth =
|
||||
0,0,
|
||||
|
||||
0,
|
||||
pkey_rsa_verifyrecover
|
||||
pkey_rsa_verifyrecover,
|
||||
|
||||
|
||||
0,0,0,0,
|
||||
|
||||
0,
|
||||
pkey_rsa_encrypt,
|
||||
|
||||
0,
|
||||
pkey_rsa_decrypt,
|
||||
|
||||
0,0
|
||||
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user