Search in sources :

Example 1 with SodiumException

use of co.krypt.krypton.exception.SodiumException in project krypton-android by kryptco.

the class EdSSHKeyPair method pgpSign.

@Override
public Signature pgpSign(HashAlgorithm hash, byte[] data) throws PGPException, NoSuchAlgorithmException, CryptoException, SignatureException, NoSuchProviderException, InvalidKeyException, InvalidKeySpecException {
    byte[] signatureBytes = signDigest(hash.digest().digest(data));
    if (signatureBytes.length != 64) {
        throw new SodiumException("unexpected signature length");
    }
    byte[] r = Arrays.copyOfRange(signatureBytes, 0, 32);
    byte[] s = Arrays.copyOfRange(signatureBytes, 32, 64);
    return new Ed25519Signature(new MPInt(r), new MPInt(s));
}
Also used : SodiumException(co.krypt.krypton.exception.SodiumException) Ed25519Signature(co.krypt.krypton.pgp.packet.Ed25519Signature) MPInt(co.krypt.krypton.pgp.packet.MPInt)

Example 2 with SodiumException

use of co.krypt.krypton.exception.SodiumException in project krypton-android by kryptco.

the class Pairing method seal.

public byte[] seal(byte[] message) throws CryptoException {
    byte[] nonce = SecureRandom.getSeed(Sodium.crypto_box_noncebytes());
    byte[] sealed = new byte[message.length + Sodium.crypto_box_macbytes()];
    if (0 != Sodium.crypto_box_easy(sealed, message, message.length, nonce, workstationPublicKey, enclaveSecretKey)) {
        throw new SodiumException("crypto_box_easy failed");
    }
    ByteArrayOutputStream nonceAndSealed = new ByteArrayOutputStream();
    try {
        nonceAndSealed.write(nonce);
        nonceAndSealed.write(sealed);
    } catch (IOException e) {
        throw new CryptoException(e.getMessage());
    }
    return nonceAndSealed.toByteArray();
}
Also used : SodiumException(co.krypt.krypton.exception.SodiumException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) CryptoException(co.krypt.krypton.exception.CryptoException)

Aggregations

SodiumException (co.krypt.krypton.exception.SodiumException)2 CryptoException (co.krypt.krypton.exception.CryptoException)1 Ed25519Signature (co.krypt.krypton.pgp.packet.Ed25519Signature)1 MPInt (co.krypt.krypton.pgp.packet.MPInt)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1