use of org.bouncycastle.crypto.params.Ed25519PublicKeyParameters in project popstellar by dedis.
the class Base64DataUtils method generatePoPToken.
/**
* @return a pseudo randomly generated valid Ed25519 keypair
*/
public static PoPToken generatePoPToken() {
byte[] privateKey = new byte[KEY_LENGTH];
RANDOM.nextBytes(privateKey);
Ed25519PrivateKeyParameters privateKeyParameters = new Ed25519PrivateKeyParameters(privateKey, 0);
Ed25519PublicKeyParameters publicKeyParameters = privateKeyParameters.generatePublicKey();
return new PoPToken(privateKey, publicKeyParameters.getEncoded());
}
use of org.bouncycastle.crypto.params.Ed25519PublicKeyParameters in project hedera-services by hashgraph.
the class Ed25519PrivateKey method fromBytes.
public static Ed25519PrivateKey fromBytes(byte[] keyBytes) {
Ed25519PrivateKeyParameters privKeyParams;
Ed25519PublicKeyParameters pubKeyParams = null;
if (keyBytes.length == Ed25519.SECRET_KEY_SIZE) {
// if the decoded bytes matches the length of a private key, try that
privKeyParams = new Ed25519PrivateKeyParameters(keyBytes, 0);
} else if (keyBytes.length == Ed25519.SECRET_KEY_SIZE + Ed25519.PUBLIC_KEY_SIZE) {
// some legacy code delivers private and public key pairs concatted together
try {
// this is how we read only the first 32 bytes
privKeyParams = new Ed25519PrivateKeyParameters(new ByteArrayInputStream(keyBytes, 0, Ed25519.SECRET_KEY_SIZE));
// read the remaining 32 bytes as the public key
pubKeyParams = new Ed25519PublicKeyParameters(keyBytes, Ed25519.SECRET_KEY_SIZE);
return new Ed25519PrivateKey(privKeyParams, pubKeyParams);
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
// decode a properly DER-encoded private key descriptor
var privateKeyInfo = PrivateKeyInfo.getInstance(keyBytes);
try {
var privateKey = privateKeyInfo.parsePrivateKey();
privKeyParams = new Ed25519PrivateKeyParameters(((ASN1OctetString) privateKey).getOctets(), 0);
var pubKeyData = privateKeyInfo.getPublicKeyData();
if (pubKeyData != null) {
pubKeyParams = new Ed25519PublicKeyParameters(pubKeyData.getOctets(), 0);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return new Ed25519PrivateKey(privKeyParams, pubKeyParams);
}
use of org.bouncycastle.crypto.params.Ed25519PublicKeyParameters in project starcoin-java by starcoinorg.
the class SignatureUtils method getPublicKey.
@SneakyThrows
public static Ed25519PublicKey getPublicKey(Ed25519PrivateKey privateKey) {
Ed25519PrivateKeyParameters key = new Ed25519PrivateKeyParameters(privateKey.value.content(), 0);
Ed25519PublicKeyParameters publicKeyParameters = key.generatePublicKey();
Ed25519PublicKey publicKey = new Ed25519PublicKey(new Bytes(publicKeyParameters.getEncoded()));
return publicKey;
}
use of org.bouncycastle.crypto.params.Ed25519PublicKeyParameters in project starcoin-java by starcoinorg.
the class SignatureUtils method multiEd25519Verify.
public static boolean multiEd25519Verify(MultiEd25519PublicKey publicKey, byte[] signingMessage, byte[] signature) {
Ed25519PublicKeyParameters key = new Ed25519PublicKeyParameters(publicKey.value.content(), 0);
Ed25519Signer signer = new Ed25519Signer();
signer.init(false, key);
signer.update(signingMessage, 0, signingMessage.length);
return signer.verifySignature(signature);
}
use of org.bouncycastle.crypto.params.Ed25519PublicKeyParameters in project starcoin-java by starcoinorg.
the class SignatureUtils method ed25519Verify.
public static boolean ed25519Verify(Ed25519PublicKey publicKey, byte[] signingMessage, byte[] signature) {
Ed25519PublicKeyParameters key = new Ed25519PublicKeyParameters(publicKey.value.content(), 0);
Ed25519Signer signer = new Ed25519Signer();
signer.init(false, key);
signer.update(signingMessage, 0, signingMessage.length);
return signer.verifySignature(signature);
}
Aggregations