Package io.github.cdimascio.ecies
Class Ecies
java.lang.Object
io.github.cdimascio.ecies.Ecies
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]decrypt(byte[] privateKeyBytes, byte[] cipherBytes) Decrypts given ciphertext with a given private keystatic StringDecrypts given ciphertext with a given private keystatic byte[]encrypt(byte[] publicKeyBytes, byte[] message) Encrypts a given message with a given public keystatic StringEncrypts a given message with a given public key in hexstatic ECKeyPairGenerates new key pair consists ofECPublicKeyandECPrivateKey
-
Constructor Details
-
Ecies
public Ecies()
-
-
Method Details
-
generateEcKeyPair
public static ECKeyPair generateEcKeyPair() throws NoSuchAlgorithmException, InvalidAlgorithmParameterExceptionGenerates 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.InvalidCipherTextException Encrypts 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.InvalidCipherTextException Decrypts 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
-