@Override protected void writePubKeyContentsIntoBuffer(PublicKey pk, Buffer<?> buf) { EdDSAPublicKey key = (EdDSAPublicKey) pk; buf.putBytes(key.getAbyte()); }
/** * @since 0.9.15 */ public static SigningPublicKey fromJavaKey(EdDSAPublicKey pk, SigType type) throws GeneralSecurityException { return new SigningPublicKey(type, pk.getAbyte()); }
/** * @since 0.9.25 */ @Override public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof EdDSAPublicKey)) return false; EdDSAPublicKey pk = (EdDSAPublicKey) o; return Arrays.equals(Abyte, pk.getAbyte()) && edDsaSpec.equals(pk.getParams()); } }
digest.update(((EdDSAPublicKey) key).getAbyte());
public static byte[] getSeedValue(EdDSAPublicKey key) { // a bit of reverse-engineering on the EdDSAPublicKeySpec return (key == null) ? null : key.getAbyte(); } }
public static byte[] getSeedValue(EdDSAPublicKey key) { // a bit of reverse-engineering on the EdDSAPublicKeySpec return (key == null) ? null : key.getAbyte(); } }
public byte[] getA() { return publicKey.getAbyte(); }
public byte[] getPublicKey() { return publicKey.getAbyte(); }
@Override protected void writePubKeyContentsIntoBuffer(PublicKey pk, Buffer<?> buf) { EdDSAPublicKey key = (EdDSAPublicKey) pk; buf.putBytes(key.getAbyte()); }
@Override public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof EdDSAPublicKey)) return false; EdDSAPublicKey pk = (EdDSAPublicKey) o; return Arrays.equals(Abyte, pk.getAbyte()) && edDsaSpec.equals(pk.getParams()); } }
/** * @return the encoded public key for this NKey * * @throws GeneralSecurityException if there is an encryption problem * @throws IOException if there is a problem encoding the public * key */ public char[] getPublicKey() throws GeneralSecurityException, IOException { if (publicKey != null) { return publicKey; } KeyPair keys = getKeyPair(); EdDSAPublicKey pubKey = (EdDSAPublicKey) keys.getPublic(); byte[] pubBytes = pubKey.getAbyte(); return encode(this.type, pubBytes); }
/** * @return the encoded public key for this NKey * * @throws GeneralSecurityException if there is an encryption problem * @throws IOException if there is a problem encoding the public * key */ public char[] getPublicKey() throws GeneralSecurityException, IOException { if (publicKey != null) { return publicKey; } KeyPair keys = getKeyPair(); EdDSAPublicKey pubKey = (EdDSAPublicKey) keys.getPublic(); byte[] pubBytes = pubKey.getAbyte(); return encode(this.type, pubBytes); }
public static boolean compareEDDSAPPublicKeys(PublicKey k1, PublicKey k2) { if (!SecurityUtils.isEDDSACurveSupported()) { return false; } if ((k1 instanceof EdDSAPublicKey) && (k2 instanceof EdDSAPublicKey)) { if (Objects.equals(k1, k2)) { return true; } else if (k1 == null || k2 == null) { return false; // both null is covered by Objects#equals } EdDSAPublicKey ed1 = (EdDSAPublicKey) k1; EdDSAPublicKey ed2 = (EdDSAPublicKey) k2; return Arrays.equals(ed1.getAbyte(), ed2.getAbyte()) && compareEDDSAKeyParams(ed1.getParams(), ed2.getParams()); } return false; }
public static boolean compareEDDSAPPublicKeys(PublicKey k1, PublicKey k2) { if (!SecurityUtils.isEDDSACurveSupported()) { return false; } if ((k1 instanceof EdDSAPublicKey) && (k2 instanceof EdDSAPublicKey)) { if (Objects.equals(k1, k2)) { return true; } else if (k1 == null || k2 == null) { return false; // both null is covered by Objects#equals } EdDSAPublicKey ed1 = (EdDSAPublicKey) k1; EdDSAPublicKey ed2 = (EdDSAPublicKey) k2; return Arrays.equals(ed1.getAbyte(), ed2.getAbyte()) && compareEDDSAKeyParams(ed1.getParams(), ed2.getParams()); } return false; }
@Override public byte[] encodePublicKey(EdDSAPublicKey publicKey) throws IOException { byte[] encoded = publicKey.getAbyte(); TypesWriter typesWriter = new TypesWriter(); typesWriter.writeString(ED25519_KEY_NAME); typesWriter.writeString(encoded, 0, encoded.length); return typesWriter.getBytes(); }
private static NKey createPair(Type type, byte[] seed) throws IOException, NoSuchProviderException, NoSuchAlgorithmException { EdDSAPrivateKeySpec privKeySpec = new EdDSAPrivateKeySpec(seed, NKey.ed25519); EdDSAPrivateKey privKey = new EdDSAPrivateKey(privKeySpec); EdDSAPublicKeySpec pubKeySpec = new EdDSAPublicKeySpec(privKey.getA(), NKey.ed25519); EdDSAPublicKey pubKey = new EdDSAPublicKey(pubKeySpec); byte[] pubBytes = pubKey.getAbyte(); byte[] bytes = new byte[pubBytes.length + seed.length]; System.arraycopy(seed, 0, bytes, 0, seed.length); System.arraycopy(pubBytes, 0, bytes, seed.length, pubBytes.length); char[] encoded = encodeSeed(type, bytes); return new NKey(type, null, encoded); }
private static NKey createPair(Type type, byte[] seed) throws IOException, NoSuchProviderException, NoSuchAlgorithmException { EdDSAPrivateKeySpec privKeySpec = new EdDSAPrivateKeySpec(seed, NKey.ed25519); EdDSAPrivateKey privKey = new EdDSAPrivateKey(privKeySpec); EdDSAPublicKeySpec pubKeySpec = new EdDSAPublicKeySpec(privKey.getA(), NKey.ed25519); EdDSAPublicKey pubKey = new EdDSAPublicKey(pubKeySpec); byte[] pubBytes = pubKey.getAbyte(); byte[] bytes = new byte[pubBytes.length + seed.length]; System.arraycopy(seed, 0, bytes, 0, seed.length); System.arraycopy(pubBytes, 0, bytes, seed.length, pubBytes.length); char[] encoded = encodeSeed(type, bytes); return new NKey(type, null, encoded); }
public void init(byte[] blob, int start, int len) throws SshException { ByteArrayReader bar = new ByteArrayReader(blob, start, len); try { String name = bar.readString(); if(!name.equals(ALGORITHM_NAME)) { throw new SshException("The encoded key is not ed25519", SshException.INTERNAL_ERROR); } byte[] pub = bar.readBinaryString(); EdDSAPublicKeySpec spec = new EdDSAPublicKeySpec(pub, EdDSANamedCurveTable.getByName("Ed25519")); publicKey = new EdDSAPublicKey(spec); if(Utils.equal(publicKey.getAbyte(), pub)==0) { throw new IOException("Not sure how to encode yet"); } } catch (IOException ioe) { throw new SshException("Failed to read encoded key data", SshException.INTERNAL_ERROR); } finally { bar.close(); } }
public byte[] getEncoded() throws SshException { ByteArrayWriter baw = new ByteArrayWriter(); try { baw.writeString(getAlgorithm()); baw.writeBinaryString(publicKey.getAbyte()); return baw.toByteArray(); } catch (IOException ex) { throw new SshException("Failed to encoded key data", SshException.INTERNAL_ERROR, ex); } finally { try { baw.close(); } catch (IOException e) { } } }
/** * Signs a message. * * @param message * message * @return */ public Signature sign(byte[] message) { try { byte[] sig; if (Native.isEnabled()) { sig = Native.sign(message, Bytes.merge(sk.getSeed(), sk.getAbyte())); } else { EdDSAEngine engine = new EdDSAEngine(); engine.initSign(sk); sig = engine.signOneShot(message); } return new Signature(sig, pk.getAbyte()); } catch (InvalidKeyException | SignatureException e) { throw new CryptoException(e); } }