Package io.github.cdimascio.ecies
Class Ecies
- java.lang.Object
-
- io.github.cdimascio.ecies.Ecies
-
public class Ecies extends Object
-
-
Constructor Summary
Constructors Constructor Description Ecies()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]decrypt(byte[] privateKeyBytes, byte[] cipherBytes)Decrypts given ciphertext with a given private keystatic Stringdecrypt(String privateKeyHex, String ciphertext)Decrypts given ciphertext with a given private keystatic byte[]encrypt(byte[] publicKeyBytes, byte[] message)Encrypts a given message with a given public keystatic Stringencrypt(String publicKeyHex, String message)Encrypts a given message with a given public key in hexstatic ECKeyPairgenerateEcKeyPair()Generates new key pair consists ofECPublicKeyandECPrivateKey
-
-
-
Method Detail
-
generateEcKeyPair
public static ECKeyPair generateEcKeyPair() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException
Generates new key pair consists ofECPublicKeyandECPrivateKey- Returns:
- new EC key pair
- Throws:
NoSuchAlgorithmExceptionInvalidAlgorithmParameterException
-
encrypt
public static String encrypt(String publicKeyHex, String message) throws org.bouncycastle.crypto.InvalidCipherTextException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, InvalidKeySpecException
Encrypts a given message with a given public key in hex- Parameters:
publicKeyHex- EC public key in hexmessage- message to encrypt- Returns:
- encrypted message with base64 encoding
- Throws:
org.bouncycastle.crypto.InvalidCipherTextExceptionInvalidAlgorithmParameterExceptionNoSuchAlgorithmExceptionInvalidKeySpecException
-
decrypt
public static String decrypt(String privateKeyHex, String ciphertext) throws org.bouncycastle.crypto.InvalidCipherTextException, NoSuchAlgorithmException, InvalidKeySpecException
Decrypts given ciphertext with a given private key- Parameters:
privateKeyHex- EC private key in hexciphertext- ciphered text in base64- Returns:
- decrypted message
- Throws:
org.bouncycastle.crypto.InvalidCipherTextExceptionNoSuchAlgorithmExceptionInvalidKeySpecException
-
encrypt
public static byte[] encrypt(byte[] publicKeyBytes, byte[] message) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, InvalidKeySpecException, org.bouncycastle.crypto.InvalidCipherTextExceptionEncrypts a given message with a given public key- Parameters:
publicKeyBytes- EC public key binarymessage- message to encrypt binary- Returns:
- encrypted message binary
- Throws:
InvalidAlgorithmParameterExceptionNoSuchAlgorithmExceptionInvalidKeySpecExceptionorg.bouncycastle.crypto.InvalidCipherTextException
-
decrypt
public static byte[] decrypt(byte[] privateKeyBytes, byte[] cipherBytes) throws NoSuchAlgorithmException, InvalidKeySpecException, org.bouncycastle.crypto.InvalidCipherTextExceptionDecrypts given ciphertext with a given private key- Parameters:
privateKeyBytes- EC private key binarycipherBytes- cipher text binary- Returns:
- decrypted message binary
- Throws:
NoSuchAlgorithmExceptionInvalidKeySpecExceptionorg.bouncycastle.crypto.InvalidCipherTextException
-
-