# null

# SecurityLocalEncryptRsa

[Valid for](../../../Shared/FeatureAvailability.md): CANoe DE • CANoe4SW DE

## Function Syntax

```
SecurityLocalEncryptRsa(byte publicKey[], dword publicKeyLength, byte plainData[], dword plainDataLength, byte cipherData[], dword* cipherDataLength, dword paddingMode)
```

## Description

Encrypts data with a given public key using asymmetric RSA encryption. Padding mode can be selected via the parameter.

## Parameters

* **publicKey**: The public key to be used for encryption in PKCS#8 format (with VSM 3.4.4 also PKCS#1 format is supported)
* **publicKeyLength**: Length of the public key to be used for encryption
* **plainData**: Data to be encrypted
* **plainDataLength**: Length of the data to be encrypted
* **cipherData \[OUT]**: Buffer to store encrypted data
* **cipherDataLength \[IN/OUT]**: Length of buffer to store encrypted data.
* **paddingMode**:
  * OAEP(SHA-256) = 1
  * OAEP(SHA-384) = 2
  * OAEP(SHA-512) = 3
  * PKCS1\_v1\_5 = 10
  * OAEP(SHA-1) = 12

## Return Values

* **1**: Success. A value of 1 means that the action was successful.
* **≤ 0**: Error. A value less than or equal to 0 means error.

## Example

```c
byte pubKey[451] = {0x2d,0x2d,0x2d,0x2d,0x2d,0x42,0x45,0x47,0x49,0x4e,0x20,0x50,0x55,0x42,0x4c,0x49,0x43,0x20,0x4b,0x45,
0x59,0x2d,0x2d,0x2d,0x2d,0x2d,0x0a,0x4d,0x49,0x49,0x42,0x49,0x6a,0x41,0x4e,0x42,0x67,0x6b,0x71,0x68,0x6b,0x69,0x47,0x39,
0x77,0x30,0x42,0x41,0x51,0x45,0x46,0x41,0x41,0x4f,0x43,0x41,0x51,0x38,0x41,0x4d,0x49,0x49,0x42,0x43,0x67,0x4b,0x43,0x41,
0x51,0x45,0x41,0x76,0x51,0x54,0x2b,0x76,0x74,0x32,0x72,0x61,0x4a,0x4d,0x63,0x2b,0x56,0x35,0x5a,0x39,0x59,0x48,0x41,0x0a,
0x6c,0x67,0x76,0x50,0x68,0x62,0x53,0x42,0x6d,0x35,0x53,0x54,0x78,0x32,0x41,0x31,0x6e,0x4a,0x33,0x4d,0x53,0x39,0x79,0x77,
0x67,0x2b,0x68,0x5a,0x2f,0x62,0x34,0x38,0x4d,0x72,0x4a,0x4a,0x4e,0x47,0x4a,0x65,0x69,0x4e,0x48,0x43,0x67,0x65,0x46,0x4e,
0x37,0x69,0x74,0x59,0x76,0x64,0x4e,0x6e,0x5a,0x53,0x7a,0x55,0x57,0x4e,0x54,0x75,0x0a,0x31,0x30,0x4a,0x78,0x4b,0x43,0x43,
0x77,0x31,0x4d,0x7a,0x74,0x46,0x69,0x4e,0x30,0x69,0x35,0x72,0x6f,0x7a,0x68,0x42,0x6e,0x56,0x66,0x2b,0x54,0x6d,0x73,0x58,
0x62,0x44,0x76,0x56,0x6c,0x68,0x63,0x33,0x6d,0x53,0x39,0x70,0x63,0x2f,0x63,0x36,0x67,0x63,0x69,0x6d,0x75,0x43,0x4e,0x4a,
0x4c,0x66,0x35,0x79,0x75,0x7a,0x48,0x7a,0x64,0x0a,0x43,0x59,0x35,0x45,0x45,0x6c,0x4d,0x75,0x6a,0x4b,0x69,0x62,0x43,0x36,
0x39,0x2b,0x53,0x74,0x6a,0x41,0x30,0x4f,0x55,0x36,0x4b,0x79,0x4a,0x51,0x6e,0x36,0x7a,0x61,0x66,0x6c,0x4d,0x53,0x66,0x4a,
0x6b,0x4a,0x68,0x45,0x4b,0x39,0x50,0x2b,0x6d,0x35,0x4c,0x38,0x5a,0x74,0x46,0x59,0x78,0x4c,0x57,0x59,0x71,0x49,0x79,0x4a,
0x6c,0x35,0x0a,0x44,0x61,0x36,0x2f,0x73,0x54,0x2b,0x53,0x61,0x51,0x72,0x4a,0x34,0x68,0x37,0x46,0x76,0x6c,0x70,0x57,0x48,
0x65,0x39,0x76,0x42,0x41,0x33,0x72,0x4c,0x66,0x6a,0x50,0x62,0x49,0x6e,0x51,0x73,0x2b,0x35,0x6d,0x75,0x56,0x65,0x6e,0x52,
0x48,0x7a,0x79,0x51,0x58,0x31,0x43,0x54,0x6b,0x30,0x4b,0x76,0x37,0x47,0x55,0x45,0x31,0x34,0x73,0x0a,0x56,0x7a,0x52,0x46,
0x2b,0x44,0x41,0x76,0x42,0x54,0x62,0x75,0x54,0x34,0x6c,0x45,0x52,0x51,0x79,0x34,0x35,0x39,0x79,0x62,0x76,0x4f,0x75,0x76,
0x54,0x6f,0x68,0x46,0x39,0x57,0x36,0x48,0x44,0x36,0x4e,0x6c,0x59,0x62,0x2f,0x78,0x47,0x41,0x75,0x31,0x73,0x76,0x56,0x62,
0x64,0x78,0x4a,0x45,0x56,0x75,0x30,0x55,0x6d,0x67,0x62,0x54,0x0a,0x34,0x77,0x49,0x44,0x41,0x51,0x41,0x42,0x0a,0x2d,0x2d,
0x2d,0x2d,0x2d,0x45,0x4e,0x44,0x20,0x50,0x55,0x42,0x4c,0x49,0x43,0x20,0x4b,0x45,0x59,0x2d,0x2d,0x2d,0x2d,0x2d,0x0a};
dword pubKeyLength = elcount(pubKey);
byte plainData[2] = {0x42, 0x42};
dword plainDataLength = elcount(plainData);
byte cipherData[1000];
dword cipherDataLength = elcount(cipherData);
dword paddingMode = 1;

long result;

result = SecurityLocalEncryptRsa(pubKey, pubKeyLength, plainData, plainDataLength, cipherData, cipherDataLength, paddingMode);
```

[SecurityLocalDecryptRsa](CAPLfunctionSecurityLocalDecryptRsa.md) • [SecurityLocalVerifyRsa](CAPLfunctionSecurityLocalVerifyRSA.md) • [SecurityLocalSignRsa](CAPLfunctionSecurityLocalSignRSA.md)
