PHPackages                             kare/kare\_enc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. kare/kare\_enc

ActiveProject[Security](/categories/security)

kare/kare\_enc
==============

RSA encryption package by kare.Consists of functions to encrypt, decrypt, generate keys etc. Scroll down for the documentation.

v1.5.0(7y ago)037MITPHPPHP &gt;=5.4

Since Dec 17Pushed 7y ago1 watchersCompare

[ Source](https://github.com/aijdissanayake/kare_enc)[ Packagist](https://packagist.org/packages/kare/kare_enc)[ RSS](/packages/kare-kare-enc/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (7)Used By (0)

KARE ENC
========

[](#kare-enc)

Composer Package - [https://packagist.org/packages/kare/kare\_enc](https://packagist.org/packages/kare/kare_enc)

[![Latest Stable Version](https://camo.githubusercontent.com/585ceb2fa7dff1c3c814b5ee253bf0076adcef3875852458bce7931ce52551b5/68747470733a2f2f706f7365722e707567782e6f72672f6b6172652f6b6172655f656e632f762f737461626c65)](https://packagist.org/packages/kare/kare_enc)[![Latest Unstable Version](https://camo.githubusercontent.com/5569f127f4cdc7b30790a45c7c34e0db02cce1a101851f1407d903558407a574/68747470733a2f2f706f7365722e707567782e6f72672f6b6172652f6b6172655f656e632f762f756e737461626c65)](https://packagist.org/packages/kare/kare_enc)[![License](https://camo.githubusercontent.com/48d09c504f95aa290f46a423efb3806c653404859dbebbb5c8a1921115b0608c/68747470733a2f2f706f7365722e707567782e6f72672f6b6172652f6b6172655f656e632f6c6963656e7365)](https://packagist.org/packages/kare/kare_enc)[![Total Downloads](https://camo.githubusercontent.com/49bb4868be0d80a3e888d7c1f234aad9667762e617e5ee4d9a31f50835bec16a/68747470733a2f2f706f7365722e707567782e6f72672f6b6172652f6b6172655f656e632f646f776e6c6f616473)](https://packagist.org/packages/kare/kare_enc)

Install
-------

[](#install)

```
$ composer require kare/kare_enc

```

Usage
-----

[](#usage)

### Initialize

[](#initialize)

```
use kare\kare_enc\RSA as RSA;
```

### Generate RSA Key Pair

[](#generate-rsa-key-pair)

`generateKeyPair(int $keyLength)` - Returns a private public key pair in the form of `pkcs8-pem` in an array with `key  => value` pairs as `['publicKey'=> $publicKey, 'privateKey'=> $privateKey}`. `$keyLength` is an optional parameter defaulted to `2048`.

##### Example :

[](#example-)

```
$keyPair = RSA::generateKeyPair(); //generates a RSA key pair of bit-length 2048 - default key length
$keyPair = RSA::generateKeyPair(4096);  //generates a RSA key pair of bit-length 4096
$pubKey = $keyPair['publicKey']; // get the public component
$pvtKey = $keyPair['privateKey']; // get the private component
```

### Import RSA Keys

[](#import-rsa-keys)

---

`importPrivateKeyString(string $keyString)` - Returns the private key corresponding to the given `pem` string.

##### Example :

[](#example--1)

```
$pvtKeyString = "-----BEGIN RSA PRIVATE KEY-----\nMIIEoQIBAAKCAQBGIdM1Sg1AEV7fR2auPildd+YQKkhzm0AbFPesm/ZaB7cSnfCb\nb9KhxSH63JVsJvK9mAT4r8ctmbKHTLkwLx6mw652g1Px7qDHAvQghkoXlsRjE2Cv\nuiIx1hAdp9QezkFaNB5yutHhOs6PJGVOnG/0zaQJ3516vtFV6PyJe/KWTvVs5Feq\naJMWi4UjOgm71q7V6/rY+cP64xplF4lZPN6v2RtsM/wxz2pr+rLvIMbNoX2y8RWR\nYRM3NWlE9dCrfh4aul6tGPdATXutgaYXHDRTGL7FxPrPI63RgsNSqxyXVq1J8ccS\ntnuB9QQ/7YbIArMf+z6FLEm32kIokn1yBQ5RAgMBAAECggEAPwKxAtXvpbp1pOI/\n7RlIjQPmnmt/AO9h33MtO9Y8tpLr9zwUK3OCqXm2l++MCMnNmm51OQKlT+Eht9JF\nKHeNcIOrwisoRtwBdAzBTl+ZPixlcia83eW8R05u2FYrjSn/KY5eNPKJE3WElLM8\nmi6PoEEKuxxAH0JGT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Uknz+2XZA==\n-----END RSA PRIVATE KEY-----";
$pvtKey = RSA::importPrivateKeyString($pvtKeyString);
```

---

`importPrivateKeyFile(string $filePath)` - Returns the private key corresponding to the given content in the `.key` file specified in the `$filePath`.

##### Example :

[](#example--2)

```
$pvtKey = RSA::importPrivateKeyFile('./keys/sample_private.key');
```

---

`importPublicKeyString(string $keyString)` - Returns the public key corresponding to the given `pem` string.

##### Example :

[](#example--3)

```
$pubKeyString = "-----BEGIN PUBLIC KEY-----\nMIIBITANBgkqhkiG9w0BAQEFAAOCAQ4AMIIBCQKCAQBGIdM1Sg1AEV7fR2auPild\nd+YQKkhzm0AbFPesm/ZaB7cSnfCbb9KhxSH63JVsJvK9mAT4r8ctmbKHTLkwLx6m\nw652g1Px7qDHAvQghkoXlsRjE2CvuiIx1hAdp9QezkFaNB5yutHhOs6PJGVOnG/0\nzaQJ3516vtFV6PyJe/KWTvVs5FeqaJMWi4UjOgm71q7V6/rY+cP64xplF4lZPN6v\n2RtsM/wxz2pr+rLvIMbNoX2y8RWRYRM3NWlE9dCrfh4aul6tGPdATXutgaYXHDRT\nGL7FxPrPI63RgsNSqxyXVq1J8ccStnuB9QQ/7YbIArMf+z6FLEm32kIokn1yBQ5R\nAgMBAAE=\n-----END PUBLIC KEY-----";
$pubKey = RSA::importPrivateKeyString($pubKeyString);
```

---

`importPublicKeyFile(string $filePath)` - Returns the public key corresponding to the given content in the `.key` file specified in the `$filePath`.

##### Example :

[](#example--4)

```
$pubKey = RSA::importPublicKeyFile('./keys/sample_public.key');
```

### Encrypt

[](#encrypt)

`publicKeyEncrypt(string $message, mixed $publicKey)` - Returns the encrypted value in `base64` format, given a string message and the public key obtained as shown above.

##### Example :

[](#example--5)

```
$encrypted = RSA::publicKeyEncrypt("abcde", $pubkey);
```

### Decrypt

[](#decrypt)

`privateKeyDecrypt(string encryptedMessage, mixed privateKey)` - Returns the derypted string value, given the encrypted value in `base64` format and the private key obtained as shown above.

##### Example :

[](#example--6)

```
$decrypted = RSA::privateKeyDecrypt($enc, $encrypted);
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

6

Last Release

2693d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f64b8f3f0be2a0dd2b18eee2f231727b6bf196619f89840a496c1f617dbbe0f3?d=identicon)[achala](/maintainers/achala)

---

Top Contributors

[![aijdissanayake](https://avatars.githubusercontent.com/u/17597680?v=4)](https://github.com/aijdissanayake "aijdissanayake (1 commits)")

---

Tags

composerpackageencryption

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kare-kare-enc/health.svg)

```
[![Health](https://phpackages.com/badges/kare-kare-enc/health.svg)](https://phpackages.com/packages/kare-kare-enc)
```

###  Alternatives

[phpseclib/phpseclib

PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.

5.6k434.8M1.3k](/packages/phpseclib-phpseclib)[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M212](/packages/defuse-php-encryption)[enlightn/security-checker

A PHP dependency vulnerabilities scanner based on the Security Advisories Database.

33732.2M110](/packages/enlightn-security-checker)[paragonie/ciphersweet

Searchable field-level encryption library for relational databases

4641.2M21](/packages/paragonie-ciphersweet)[jorijn/laravel-security-checker

Added Laravel functionality to the Enlightn Security Checker. Adds a command to check for, and optionally emails you, vulnerabilities when they affect you.

2021.8M1](/packages/jorijn-laravel-security-checker)[ass/xmlsecurity

The XmlSecurity library is written in PHP for working with XML Encryption and Signatures

955.6M30](/packages/ass-xmlsecurity)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
