-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from /issues/263
Issues/263 - Merge in com.syntifi.crypto sources
- Loading branch information
Showing
45 changed files
with
14,459 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
sbs4jVersion=0.1.8 | ||
bouncyCastleVersion=1.69 | ||
commonsIoVersion=2.11.0 | ||
cryptokeyVersion=0.4.0 | ||
cxfRtRsSseVersion=3.5.5 | ||
lombokPluginVersion=6.2.0 | ||
jupiterVersion=5.9.0 | ||
jsonrpc4jVersion=1.6.1-oak | ||
jacksonVersion=2.13.4 | ||
javaTuplesVersion=1.2 | ||
jodaTimeVersion=2.11.1 | ||
jsonassertVersion=1.5.1 | ||
jsonPathAssertVersion=2.7.0 | ||
jsonrpc4jVersion=1.6.1-oak | ||
jupiterVersion=5.9.0 | ||
mockwebserverVersion=4.10.0 | ||
log4jVersion=2.18.0 | ||
lombokPluginVersion=6.2.0 | ||
sbs4jVersion=0.1.8 | ||
slf4jApiVersion=2.0.0 | ||
javaTuplesVersion=1.2 | ||
jodaTimeVersion=2.11.1 | ||
web3jVersion=5.0.0 |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/casper/sdk/exception/InvalidKeyBytesException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.casper.sdk.exception; | ||
|
||
/** | ||
* @author [email protected] | ||
*/ | ||
public class InvalidKeyBytesException extends RuntimeException { | ||
|
||
public InvalidKeyBytesException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.syntifi.crypto.key; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import org.bouncycastle.asn1.ASN1ObjectIdentifier; | ||
|
||
/** | ||
* ASN1 identifiers for working with key cryptography | ||
* | ||
* @author Alexandre Carvalho | ||
* @author Andre Bertolace | ||
* @since 0.1.0 | ||
*/ | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class ASN1Identifiers { | ||
|
||
public static final ASN1ObjectIdentifier Secp256k1OIDCurve = new ASN1ObjectIdentifier("1.3.132.0.10"); | ||
public static final ASN1ObjectIdentifier Secp256k1OIDkey = new ASN1ObjectIdentifier("1.2.840.10045.2.1"); | ||
|
||
public static final ASN1ObjectIdentifier Ed25519OID = new ASN1ObjectIdentifier("1.3.101.112"); | ||
|
||
public static final String PUBLIC_KEY_DER_HEADER = "PUBLIC KEY"; | ||
public static final String PRIVATE_KEY_DER_HEADER = "PRIVATE KEY"; | ||
public static final String EC_PRIVATE_KEY_DER_HEADER = "EC PRIVATE KEY"; | ||
} |
86 changes: 86 additions & 0 deletions
86
src/main/java/com/syntifi/crypto/key/AbstractPrivateKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.syntifi.crypto.key; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.io.*; | ||
import java.security.GeneralSecurityException; | ||
|
||
/** | ||
* Abstract class for needed shared functionalities | ||
* | ||
* @author Alexandre Carvalho | ||
* @author Andre Bertolace | ||
* @since 0.1.0 | ||
*/ | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public abstract class AbstractPrivateKey { | ||
|
||
private byte[] key; | ||
|
||
/** | ||
* Loads a private key from a byte array | ||
* | ||
* @param privateKey the private key bytes | ||
*/ | ||
public abstract void loadPrivateKey(final byte[] privateKey) throws IOException; | ||
|
||
/** | ||
* Reads the private key from a file | ||
* | ||
* @param filename the source filename | ||
* @throws IOException thrown if an error occurs reading the file | ||
*/ | ||
public final void readPrivateKey(final String filename) throws IOException { | ||
try (final Reader fileReader = new FileReader(filename)) { | ||
readPrivateKey(fileReader); | ||
} | ||
} | ||
|
||
/** | ||
* Reads the private key from a stream | ||
* | ||
* @param reader the source of the private key | ||
* @throws IOException thrown if an error occurs reading the file | ||
*/ | ||
public abstract void readPrivateKey(final Reader reader) throws IOException; | ||
|
||
/** | ||
* Writes the private key to a file | ||
* | ||
* @param filename the target filename | ||
* @throws IOException thrown if an error occurs writing the file | ||
*/ | ||
public final void writePrivateKey(final String filename) throws IOException { | ||
try (final Writer fileWriter = new FileWriter(filename)) { | ||
writePrivateKey(fileWriter); | ||
} | ||
} | ||
|
||
/** | ||
* Writes the private key to a file | ||
* | ||
* @param writer the target writer | ||
* @throws IOException thrown if an error occurs writing the file | ||
*/ | ||
public abstract void writePrivateKey(final Writer writer) throws IOException; | ||
|
||
/** | ||
* Signs a message with the loaded key | ||
* | ||
* @param message message to sign | ||
* @return signed message | ||
* @throws GeneralSecurityException thrown if an error occurs processing message or signature | ||
*/ | ||
public abstract byte[] sign(final byte[] message) throws GeneralSecurityException; | ||
|
||
/** | ||
* Derives the public key from the loaded private key | ||
* | ||
* @return the derived {@link AbstractPublicKey} | ||
*/ | ||
public abstract AbstractPublicKey derivePublicKey(); | ||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/com/syntifi/crypto/key/AbstractPublicKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.syntifi.crypto.key; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.io.*; | ||
import java.security.GeneralSecurityException; | ||
|
||
/** | ||
* Abstract class for needed shared functionalities | ||
* | ||
* @author Alexandre Carvalho | ||
* @author Andre Bertolace | ||
* @since 0.1.0 | ||
*/ | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public abstract class AbstractPublicKey { | ||
|
||
private byte[] key; | ||
|
||
/** | ||
* Loads a public key from a byte array | ||
* | ||
* @param publicKey the public key bytes | ||
*/ | ||
public abstract void loadPublicKey(final byte[] publicKey) throws IOException; | ||
|
||
/** | ||
* Reads the public key from a file | ||
* | ||
* @param filename the source filename | ||
* @throws IOException thrown if an error occurs reading the file | ||
*/ | ||
public final void readPublicKey(final String filename) throws IOException { | ||
try (final Reader fileReader = new FileReader(filename)) { | ||
readPublicKey(fileReader); | ||
} | ||
} | ||
|
||
/** | ||
* Reads the public key from a file | ||
* | ||
* @param reader the source filename | ||
* @throws IOException thrown if an error occurs reading the file | ||
*/ | ||
public abstract void readPublicKey(final Reader reader) throws IOException; | ||
|
||
/** | ||
* Writes the public key to a file | ||
* | ||
* @param filename the target filename | ||
* @throws IOException thrown if an error occurs writing the file | ||
*/ | ||
public final void writePublicKey(final String filename) throws IOException { | ||
try (final Writer fileWriter = new FileWriter(filename)) { | ||
writePublicKey(fileWriter); | ||
} | ||
} | ||
|
||
/** | ||
* Writes the public key to a file | ||
* | ||
* @param writer the target to write the public key | ||
* @throws IOException thrown if an error occurs writing the file | ||
*/ | ||
public abstract void writePublicKey(final Writer writer) throws IOException; | ||
|
||
/** | ||
* Verifies message with given signature | ||
* | ||
* @param message the signed message | ||
* @param signature the signature to check against | ||
* @return true if matches, false otherwise | ||
* @throws GeneralSecurityException thrown if an error occurs processing message and signature | ||
*/ | ||
public abstract Boolean verify(final byte[] message, final byte[] signature) throws GeneralSecurityException; | ||
} |
Oops, something went wrong.