Package io.keyko.common.helpers
Class CryptoHelper
- java.lang.Object
-
- io.keyko.common.helpers.CryptoHelper
-
public abstract class CryptoHelper extends Object
Helper abstract class with crypto utility methods
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_ALGORITHM
static int
DEFAULT_KEY_SIZE
private static char[]
DIGITS
The Constant DIGITS.private static BigInteger
MASK_256
-
Constructor Summary
Constructors Constructor Description CryptoHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]
decrypt(byte[] privateKey, byte[] inputData)
Given a private key and some encrypted data tries to decrypt the data using the private keystatic byte[]
decrypt(byte[] privateKey, byte[] inputData, String algorithm)
Given a private key and some encrypted data tries to decrypt the data using the private keystatic byte[]
encrypt(byte[] publicKey, byte[] inputData)
Given a public key and input data encrypts the input data using the public key.static byte[]
encrypt(byte[] publicKey, byte[] inputData, String algorithm)
Given a public key and input data encrypts the input data using the public key.static KeyPair
generateECSDAKeyPair()
Generates a KeyPairstatic KeyPair
generateKeyPair()
Generates a KeyPairstatic KeyPair
generateKeyPair(String algorithm, int keySize)
Generates a ECSDA KeyPairstatic String
getHex(byte[] data)
Gets the hex.static byte[]
keccak256(String input)
Given an input string generates the equivalent to keccak256(abi.encodePacked())static String
sha3_256(String input)
Given an input string generates the digest SHA3 256 hashstatic String
sha3256(String input)
Given an input string return the result of sha3256static byte[]
soliditySha3(Object... data)
Given N objects, return the SHA3 of those objectsstatic byte[]
toBytes(Object obj)
Given an object (byte[], BigInteger, Address, Uint or Number) gets the byte[] with the proper length
-
-
-
Field Detail
-
DEFAULT_ALGORITHM
public static final String DEFAULT_ALGORITHM
- See Also:
- Constant Field Values
-
DEFAULT_KEY_SIZE
public static final int DEFAULT_KEY_SIZE
- See Also:
- Constant Field Values
-
DIGITS
private static final char[] DIGITS
The Constant DIGITS.
-
MASK_256
private static final BigInteger MASK_256
-
-
Method Detail
-
encrypt
public static byte[] encrypt(byte[] publicKey, byte[] inputData) throws CryptoException
Given a public key and input data encrypts the input data using the public key. So only the holder of the private key can decrypt the data- Parameters:
publicKey
- public key byte[]inputData
- data to encrypt []- Returns:
- encrypted bytes
- Throws:
CryptoException
- Encryption error
-
encrypt
public static byte[] encrypt(byte[] publicKey, byte[] inputData, String algorithm) throws CryptoException
Given a public key and input data encrypts the input data using the public key. So only the holder of the private key can decrypt the data- Parameters:
publicKey
- public key byte[]inputData
- data to encrypt []algorithm
- algorithm to use- Returns:
- encrypted bytes
- Throws:
CryptoException
- Encryption error
-
decrypt
public static byte[] decrypt(byte[] privateKey, byte[] inputData) throws CryptoException
Given a private key and some encrypted data tries to decrypt the data using the private key- Parameters:
privateKey
- private key byte[]inputData
- encrypted input data- Returns:
- decrypted data
- Throws:
CryptoException
- Decryption error
-
decrypt
public static byte[] decrypt(byte[] privateKey, byte[] inputData, String algorithm) throws CryptoException
Given a private key and some encrypted data tries to decrypt the data using the private key- Parameters:
privateKey
- private key byte[]inputData
- encrypted input dataalgorithm
- algorithm to use- Returns:
- decrypted data
- Throws:
CryptoException
- Decryption error
-
generateKeyPair
public static KeyPair generateKeyPair() throws CryptoException
Generates a KeyPair- Returns:
- KeyPair
- Throws:
CryptoException
- error generating key pair
-
generateKeyPair
public static KeyPair generateKeyPair(String algorithm, int keySize) throws CryptoException
Generates a ECSDA KeyPair- Parameters:
algorithm
- Algorithm to usekeySize
- key size- Returns:
- KeyPair
- Throws:
CryptoException
- error generating key pair
-
generateECSDAKeyPair
public static KeyPair generateECSDAKeyPair() throws CryptoException
Generates a KeyPair- Returns:
- KeyPair
- Throws:
CryptoException
- error generating key pair
-
sha3_256
public static String sha3_256(String input)
Given an input string generates the digest SHA3 256 hash- Parameters:
input
-- Returns:
-
keccak256
public static byte[] keccak256(String input)
Given an input string generates the equivalent to keccak256(abi.encodePacked())- Parameters:
input
-- Returns:
-
sha3256
public static String sha3256(String input)
Given an input string return the result of sha3256- Parameters:
input
- string- Returns:
- hashed message
-
soliditySha3
public static byte[] soliditySha3(Object... data)
Given N objects, return the SHA3 of those objects- Parameters:
data
- objects- Returns:
- sha3
-
getHex
public static String getHex(byte[] data)
Gets the hex.- Parameters:
data
- the data- Returns:
- the hex
-
toBytes
public static byte[] toBytes(Object obj)
Given an object (byte[], BigInteger, Address, Uint or Number) gets the byte[] with the proper length- Parameters:
obj
- the object- Returns:
- byte[]
-
-