org.bouncycastle.asn1.edec.EdECObjectIdentifiers Java Examples

The following examples show how to use org.bouncycastle.asn1.edec.EdECObjectIdentifiers. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SignatureVerificationService.java    From guardedbox with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * This method gets called after the bean is created.
 */
@PostConstruct
private void postConstruct() {

    // Set signatureAlgorithmId.
    try {

        signatureAlgorithmId = new AlgorithmIdentifier((ASN1ObjectIdentifier) EdECObjectIdentifiers.class
                .getDeclaredField("id_" + cryptographyProperties.getSignatureAlgorithm()).get(null));

    } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
        throw new RuntimeException(String.format(
                "Error creating the AlgorithmIdentifier corresponding to the signature algorithm %s",
                cryptographyProperties.getSignatureAlgorithm()));
    }

}
 
Example #2
Source File: ExtendedPrivKey.java    From jlibra with Apache License 2.0 5 votes vote down vote up
public ExtendedPrivKey(SecretKey secretKey) {
    Ed25519PrivateKeyParameters pKeyParams = new Ed25519PrivateKeyParameters(secretKey.getByteSequence().toArray(),
            0);

    try {
        PrivateKeyInfo keyInfo = PrivateKeyInfoFactory.createPrivateKeyInfo(pKeyParams);
        this.privateKey = KeyUtils.getKeyFactory().generatePrivate(new PKCS8EncodedKeySpec(keyInfo.getEncoded()));
        this.publicKey = BouncyCastleProvider.getPublicKey(new SubjectPublicKeyInfo(
                new AlgorithmIdentifier(EdECObjectIdentifiers.id_Ed25519), keyInfo.getPublicKeyData().getBytes()));
    } catch (IOException | InvalidKeySpecException e) {
        throw new LibraRuntimeException("Key creation failed", e);
    }
}
 
Example #3
Source File: Ed25519PrivateKey.java    From hedera-sdk-java with Apache License 2.0 5 votes vote down vote up
private PrivateKeyInfo toPrivateKeyInfo() {
    try {
        return new PrivateKeyInfo(
            new AlgorithmIdentifier(EdECObjectIdentifiers.id_Ed25519),
            new DEROctetString(privKeyParams.getEncoded()));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example #4
Source File: PublicKey.java    From hedera-sdk-java with Apache License 2.0 5 votes vote down vote up
public static PublicKey fromString(String keyString) {
    SubjectPublicKeyInfo pubKeyInfo;

    try {
        byte[] keyBytes = Hex.decode(keyString);

        // it could be a hex-encoded raw public key or a DER-encoded public key
        if (keyBytes.length == Ed25519.PUBLIC_KEY_SIZE) {
            return Ed25519PublicKey.fromBytes(keyBytes);
        }

        pubKeyInfo = SubjectPublicKeyInfo.getInstance(keyBytes);
    } catch (Exception e) {
        throw new IllegalArgumentException("Failed to parse public key", e);
    }

    ASN1ObjectIdentifier algId = pubKeyInfo.getAlgorithm()
        .getAlgorithm();

    if (algId.equals(EdECObjectIdentifiers.id_Ed25519)) {
        return Ed25519PublicKey.fromBytes(
            pubKeyInfo.getPublicKeyData()
                .getBytes());
    } else {
        throw new IllegalArgumentException("Unsupported public key type: " + algId.toString());
    }
}
 
Example #5
Source File: DNSSECWithBC.java    From dnsjava with BSD 2-Clause "Simplified" License 5 votes vote down vote up
static PublicKey toPublicKey(int alg, byte[] key)
    throws DNSSECException, GeneralSecurityException, IOException {
  switch (alg) {
    case Algorithm.ED25519:
      return toEdDSAPublicKey(key, EdECObjectIdentifiers.id_Ed25519);
    case Algorithm.ED448:
      return toEdDSAPublicKey(key, EdECObjectIdentifiers.id_Ed448);
    default:
      throw new UnsupportedAlgorithmException(alg);
  }
}