use of co.krypt.krypton.exception.CryptoException in project krypton-android by kryptco.
the class EdSSHKeyPair method signDigestAppendingPubkey.
@Override
public byte[] signDigestAppendingPubkey(byte[] data, String algo) throws CryptoException {
try {
ByteArrayOutputStream dataWithPubkey = new ByteArrayOutputStream();
dataWithPubkey.write(data);
dataWithPubkey.write(SSHWire.encode(publicKeySSHWireFormat()));
byte[] signaturePayload = dataWithPubkey.toByteArray();
return signDigest(signaturePayload);
} catch (IOException | SignatureException | InvalidKeyException e) {
e.printStackTrace();
throw new CryptoException(e);
}
}
use of co.krypt.krypton.exception.CryptoException in project krypton-android by kryptco.
the class RSAKeyManager method loadOrGenerateNoDigestKeyPair.
/*
For backwards compatibility testing
*/
@Deprecated
public SSHKeyPairI loadOrGenerateNoDigestKeyPair(String tag) throws CryptoException {
synchronized (lock) {
try {
KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
keyStore.load(null);
KeyStore.Entry privateKeyEntry = keyStore.getEntry(tag, null);
if (privateKeyEntry instanceof KeyStore.PrivateKeyEntry) {
return new RSASSHKeyPair(new KeyPair(((KeyStore.PrivateKeyEntry) privateKeyEntry).getCertificate().getPublicKey(), ((KeyStore.PrivateKeyEntry) privateKeyEntry).getPrivateKey()), 0);
} else {
Log.w(LOG_TAG, "Not an instance of a PrivateKeyEntry");
}
KeyPair keyPair = null;
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA, "AndroidKeyStore");
keyPairGenerator.initialize(new KeyGenParameterSpec.Builder(tag, KeyProperties.PURPOSE_SIGN).setDigests(KeyProperties.DIGEST_NONE).setSignaturePaddings(KeyProperties.SIGNATURE_PADDING_RSA_PKCS1).setKeySize(3072).setUserAuthenticationRequired(false).build());
long genStart = System.currentTimeMillis();
keyPair = keyPairGenerator.generateKeyPair();
long genStop = System.currentTimeMillis();
Log.i(LOG_TAG, "KeyGen took " + String.valueOf((genStop - genStart)));
return new RSASSHKeyPair(keyPair, 0);
} catch (CertificateException e) {
throw new CryptoException(e.getMessage());
} catch (InvalidAlgorithmParameterException e) {
throw new CryptoException(e.getMessage());
} catch (IOException e) {
throw new CryptoException(e.getMessage());
} catch (KeyStoreException e) {
throw new CryptoException(e.getMessage());
} catch (NoSuchAlgorithmException e) {
throw new CryptoException(e.getMessage());
} catch (NoSuchProviderException e) {
throw new CryptoException(e.getMessage());
} catch (ProviderException e) {
throw new CryptoException(e.getMessage());
} catch (UnrecoverableEntryException e) {
throw new CryptoException(e.getMessage());
} catch (UnsupportedOperationException e) {
throw new CryptoException(e.getMessage());
}
}
}
use of co.krypt.krypton.exception.CryptoException 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();
}
Aggregations