# ECC Encryption

**URL:** https://discuss.kotlinlang.org/t/ecc-encryption/19876
**Category:** Support
**Created:** [November 10, 2020, 9:02pm UTC](https://discuss.kotlinlang.org/t/ecc-encryption/19876 "2020-11-10T21:02:51Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Cherimos](https://avatars.discourse-cdn.com/v4/letter/c/a6a055/32.png) [@Cherimos](https://discuss.kotlinlang.org/u/Cherimos)
#### Post date: [November 10, 2020, 9:02pm UTC](https://discuss.kotlinlang.org/t/ecc-encryption/19876/1 "2020-11-10T21:02:51Z")

</div>

Is there any information or library about Ecliptic Encryption within Kotlin?  
For generating key pairs and encrypting, decrypting messages.  
There is very little to non information about this topic.

I want to implement the ECDH 512 bit for example.  
Is it maybe possible to use the Java version within Kotlin?  
And how do we implement this?

Thanks in advance.

---

<div class="post-metadata">

### Author: ![Beholder](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/beholder/32/2078_2.png) [@Beholder](https://discuss.kotlinlang.org/u/Beholder)
#### Post date: [November 11, 2020, 2:23pm UTC](https://discuss.kotlinlang.org/t/ecc-encryption/19876/2 "2020-11-11T14:23:51Z")

</div>

You probably can look at [Bouncy Castle](https://www.bouncycastle.org/java.html)

---

<div class="post-metadata">

### Author: ![fvasco](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/fvasco/32/1961_2.png) [@fvasco](https://discuss.kotlinlang.org/u/fvasco)
#### Post date: [November 11, 2020, 3:25pm UTC](https://discuss.kotlinlang.org/t/ecc-encryption/19876/3 "2020-11-11T15:25:07Z")

</div>

> [@Cherimos](#):
>
> Is it maybe possible to use the Java version within Kotlin?

Almost always

> [@Cherimos](#):
>
> And how do we implement this?

Like Java.  
You can consider the Java to Kotlin converter.

---

<div class="post-metadata">

### Author: ![Wasabi375](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wasabi375/32/4741_2.png) [@Wasabi375](https://discuss.kotlinlang.org/u/Wasabi375)
#### Post date: [November 11, 2020, 3:32pm UTC](https://discuss.kotlinlang.org/t/ecc-encryption/19876/4 "2020-11-11T15:32:07Z")

</div>

> [@fvasco](#):
>
> > [@Cherimos](#):
> >
> > And how do we implement this?
> 
> Like Java.  
> You can consider the Java to Kotlin converter.

You can use any java library as if it is written in kotlin.

---

<div class="post-metadata">

### Author: ![Cherimos](https://avatars.discourse-cdn.com/v4/letter/c/a6a055/32.png) [@Cherimos](https://discuss.kotlinlang.org/u/Cherimos)
#### Post date: [November 14, 2020, 6:46pm UTC](https://discuss.kotlinlang.org/t/ecc-encryption/19876/5 "2020-11-14T18:46:03Z")

</div>

Thank you for your reactions.  
Is there any basic/beginner information about bouncy castle to implement this the right way in Android?  
There is a ton of information, which I don’t mind.  
But where to start?

---

<div class="post-metadata">

### Author: ![Cherimos](https://avatars.discourse-cdn.com/v4/letter/c/a6a055/32.png) [@Cherimos](https://discuss.kotlinlang.org/u/Cherimos)
#### Post date: [November 15, 2020, 10:28am UTC](https://discuss.kotlinlang.org/t/ecc-encryption/19876/6 "2020-11-15T10:28:13Z")

</div>

This is what I have so far.

```
Security.removeProvider("BC")
Security.insertProviderAt(BouncyCastleProvider(), 1)

val keyGen: KeyPairGenerator = KeyPairGenerator.getInstance("EC")
val random: SecureRandom = SecureRandom.getInstance("SHA1PRNG")
keyGen.initialize(256, random)

val pair: KeyPair = keyGen.generateKeyPair()

val privateKey: PrivateKey = pair.getPrivate()
val publicKey: PublicKey = pair.getPublic()

```

Do have I have to make a KeyAgreement first before I encrypt and decrypt messages?
