Tabnine Logo
InvalidKeyException
Code IndexAdd Tabnine to your IDE (free)

How to use
InvalidKeyException
in
java.security

Best Java code snippets using java.security.InvalidKeyException (Showing top 20 results out of 2,331)

Refine searchRefine arrow

  • IllegalBlockSizeException
  • BadPaddingException
  • NoSuchAlgorithmException
  • InvalidAlgorithmParameterException
  • SecretKeySpec
  • Cipher
  • NoSuchPaddingException
origin: robovm/robovm

  Cipher cipher = Cipher.getInstance(algName);
  if (algParameters == null) {
    cipher.init(Cipher.DECRYPT_MODE, decryptKey);
  } else {
    cipher.init(Cipher.DECRYPT_MODE, decryptKey, algParameters);
  byte[] decryptedData = cipher.doFinal(encryptedData);
  throw new NoSuchAlgorithmException(e.getMessage());
} catch (InvalidAlgorithmParameterException e) {
  throw new NoSuchAlgorithmException(e.getMessage());
} catch (IllegalStateException e) {
  throw new InvalidKeyException(e.getMessage());
} catch (IllegalBlockSizeException e) {
  throw new InvalidKeyException(e.getMessage());
} catch (BadPaddingException e) {
  throw new InvalidKeyException(e.getMessage());
origin: oracle/helidon

private Optional<String> validateRsaSha256(SecurityEnvironment env,
                      InboundClientDefinition clientDefinition) {
  try {
    Signature signature = Signature.getInstance("SHA256withRSA");
    signature.initVerify(clientDefinition.keyConfig()
                   .orElseThrow(() -> new HttpSignatureException("RSA public key configuration is "
                                              + "required"))
                   .publicKey()
                   .orElseThrow(() -> new HttpSignatureException(
                       "Public key is required, yet not configured")));
    signature.update(getBytesToSign(env, null));
    if (!signature.verify(this.signatureBytes)) {
      return Optional.of("Signature is not valid");
    }
    return Optional.empty();
  } catch (NoSuchAlgorithmException e) {
    LOGGER.log(Level.FINEST, "SHA256withRSA algorithm not found", e);
    return Optional.of("SHA256withRSA algorithm not found: " + e.getMessage());
  } catch (InvalidKeyException e) {
    LOGGER.log(Level.FINEST, "Invalid RSA key", e);
    return Optional.of("Invalid RSA key: " + e.getMessage());
  } catch (SignatureException e) {
    LOGGER.log(Level.FINEST, "Signature exception", e);
    return Optional.of("SignatureException: " + e.getMessage());
  }
}
origin: aa112901/remusic

private static byte[] decrypt(byte[] content, String password) {
  try {
    byte[] keyStr = getKey(password);
    SecretKeySpec key = new SecretKeySpec(keyStr, "AES");
    Cipher cipher = Cipher.getInstance(algorithmStr);//algorithmStr
    cipher.init(Cipher.DECRYPT_MODE, key);//   ʼ
    byte[] result = cipher.doFinal(content);
    return result; //
  } catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
  } catch (NoSuchPaddingException e) {
    e.printStackTrace();
  } catch (InvalidKeyException e) {
    e.printStackTrace();
  } catch (IllegalBlockSizeException e) {
    e.printStackTrace();
  } catch (BadPaddingException e) {
    e.printStackTrace();
  }
  return null;
}
origin: wildfly/wildfly

@Override
public final InvalidKeyException invalidKeyNoSuchMessageDigestAlgorithm(final String algorithm) {
  final InvalidKeyException result = new InvalidKeyException(String.format(getLoggingLocale(), invalidKeyNoSuchMessageDigestAlgorithm$str(), algorithm));
  final StackTraceElement[] st = result.getStackTrace();
  result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
  return result;
}
private static final String invalidKeyCannotVerifyPassword = "ELY08015: Cannot verify password";
origin: aa112901/remusic

private static byte[] encrypt(byte[] content, byte[] keyBytes) {
  byte[] encryptedText = null;
  if (!isInited) {
    init();
  }
  /**
   *类 SecretKeySpec
   *可以使用此类来根据一个字节数组构造一个 SecretKey,
   *而无须通过一个(基于 provider 的)SecretKeyFactory。
   *此类仅对能表示为一个字节数组并且没有任何与之相关联的钥参数的原始密钥有用
   *构造方法根据给定的字节数组构造一个密钥。
   *此构造方法不检查给定的字节数组是否指定了一个算法的密钥。
   */
  Key key = new SecretKeySpec(keyBytes, "AES");
  try {
    // 用密钥初始化此 cipher。
    cipher.init(Cipher.ENCRYPT_MODE, key);
  } catch (InvalidKeyException e) {
    e.printStackTrace();
  }
  try {
    //按单部分操作加密或解密数据,或者结束一个多部分操作。(不知道神马意思)
    encryptedText = cipher.doFinal(content);
  } catch (IllegalBlockSizeException e) {
    e.printStackTrace();
  } catch (BadPaddingException e) {
    e.printStackTrace();
  }
  return encryptedText;
}
origin: robovm/robovm

        NoSuchAlgorithmException, InvalidKeyException {
if (key == null) {
  throw new InvalidKeyException("key == null");
  Cipher cipher = Cipher.getInstance(sealAlg);
  if ((paramsAlg != null) && (paramsAlg.length() != 0)) {
    AlgorithmParameters params =
      AlgorithmParameters.getInstance(paramsAlg);
    params.init(encodedParams);
    cipher.init(Cipher.DECRYPT_MODE, key, params);
  } else {
    cipher.init(Cipher.DECRYPT_MODE, key);
  byte[] serialized = cipher.doFinal(encryptedContent);
  throw new NoSuchAlgorithmException(e.toString());
} catch (InvalidAlgorithmParameterException e) {
  throw new NoSuchAlgorithmException(e.toString());
} catch (IllegalBlockSizeException e) {
  throw new NoSuchAlgorithmException(e.toString());
} catch (BadPaddingException e) {
  throw new NoSuchAlgorithmException(e.toString());
} catch (IllegalStateException  e) {
origin: com.braintreepayments/encryption

public static String encrypt(byte[] data, String publicKeyString) throws BraintreeEncryptionException {
  Cipher rsa;
  try {
    rsa = Cipher.getInstance(TRANSFORMATION);
    PublicKey publicKey = publicKey(publicKeyString);
    rsa.init(Cipher.ENCRYPT_MODE, publicKey);
    byte[] encodedData = Base64.encode(data);
    byte[] encryptedData = rsa.doFinal(encodedData);
    return new String(Base64.encode(encryptedData));
  } catch (NoSuchAlgorithmException e) {
    throw new BraintreeEncryptionException("No Such Algorithm: " + e.getMessage());
  } catch (NoSuchPaddingException e) {
    throw new BraintreeEncryptionException("No Such Padding: " + e.getMessage());
  } catch (InvalidKeyException e) {
    throw new BraintreeEncryptionException("Invalid Key: " + e.getMessage());
  } catch (IllegalBlockSizeException e) {
    throw new BraintreeEncryptionException("Illegal Block Size: " + e.getMessage());
  } catch (BadPaddingException e) {
    throw new BraintreeEncryptionException("Bad Padding: " + e.getMessage());
  }
}
origin: knowm/XChange

 private String generateHash(String ApiKey, String timestamp) {
  Mac sha256_HMAC = null;
  String message = ApiKey + timestamp;

  try {
   sha256_HMAC = Mac.getInstance(HMAC_SHA_256);
   SecretKeySpec keySpec = new SecretKeySpec(SecretKey, HMAC_SHA_256);
   sha256_HMAC.init(keySpec);
   return Base64.getEncoder().encodeToString(sha256_HMAC.doFinal(message.getBytes()));

  } catch (NoSuchAlgorithmException e) {
   e.printStackTrace();
  } catch (InvalidKeyException e) {
   e.printStackTrace();
  }
  return "";
 }
}
origin: com.madgag.spongycastle/bctls-jdk15on

public void setKey(byte[] key, int keyOff, int keyLen)
{
  try
  {
    mac.init(new SecretKeySpec(key, keyOff, keyLen, algorithm));
  }
  catch (InvalidKeyException e)
  {
    e.printStackTrace();
  }
}
origin: com.aliyun/aliyun-java-sdk-core

@Override
public String signString(String stringToSign, String accessKeySecret) {
  try {
    Mac mac = Mac.getInstance(ALGORITHM_NAME);
    mac.init(new SecretKeySpec(accessKeySecret.getBytes(ENCODING), ALGORITHM_NAME));
    byte[] signData = mac.doFinal(stringToSign.getBytes(ENCODING));
    return DatatypeConverter.printBase64Binary(signData);
  } catch (NoSuchAlgorithmException e) {
    throw new IllegalArgumentException(e.toString());
  } catch (UnsupportedEncodingException e) {
    throw new IllegalArgumentException(e.toString());
  } catch (InvalidKeyException e) {
    throw new IllegalArgumentException(e.toString());
  }
}
origin: org.conscrypt/conscrypt-openjdk-uber

  @Override
  protected SecretKey engineTranslateKey(SecretKey secretKey) throws InvalidKeyException {
    if (secretKey == null) {
      throw new InvalidKeyException("Null SecretKey");
    }
    return new SecretKeySpec(secretKey.getEncoded(), secretKey.getAlgorithm());
  }
}
origin: com.nimbusds/nimbus-jose-jwt

/**
 * Enumeration of the Elliptic Curve Diffie-Hellman Ephemeral Static
 * algorithm modes.
 */
public enum AlgorithmMode {
  /**
   * Direct key agreement mode.
   */
  DIRECT,
  /**
   * Key wrapping mode.
   */
  KW
}
origin: com.orientechnologies/orientdb-core

private Cipher getAndInitializeCipher(final int mode, final byte[] nonce) {
 try {
  Cipher cipher = CIPHER.get();
  cipher.init(mode, key, gcmParameterSpec(nonce));
  return cipher;
 } catch (InvalidKeyException e) {
  throw OException.wrapException(new OInvalidStorageEncryptionKeyException(e.getMessage()), e);
 } catch (InvalidAlgorithmParameterException e) {
  throw new IllegalArgumentException("Invalid or re-used nonce.", e);
 }
}
origin: schwabe/ics-openvpn

@Override
public byte[] getSignedData(String alias, byte[] data) throws RemoteException {
  try {
    return SimpleSigner.signData(data);
  } catch (IOException e) {
    e.printStackTrace();
  } catch (NoSuchPaddingException e) {
    e.printStackTrace();
  } catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
  } catch (IllegalBlockSizeException e) {
    e.printStackTrace();
  } catch (BadPaddingException e) {
    e.printStackTrace();
  } catch (InvalidKeySpecException e) {
    e.printStackTrace();
  } catch (InvalidKeyException e) {
    e.printStackTrace();
  }
  // Something failed, return null
  return null;
}
origin: ibinti/bugvm

protected void engineInit(
  int                 opmode,
  Key                 key,
  SecureRandom        random) 
  throws InvalidKeyException
{
  try
  {
    engineInit(opmode, key, (AlgorithmParameterSpec)null, random);
  }
  catch (InvalidAlgorithmParameterException e)
  {
    throw new InvalidKeyException(e.getMessage());
  }
}
origin: wildfly/wildfly

@Override
boolean verify(char[] guess) throws InvalidKeyException {
  // The OTP SASL mechanism handles this (this involves updating the stored password)
  throw new InvalidKeyException();
}
origin: jwtk/jjwt

@Override
public byte[] sign(byte[] data) {
  try {
    return doSign(data);
  } catch (InvalidKeyException e) {
    throw new SignatureException("Invalid RSA PrivateKey. " + e.getMessage(), e);
  } catch (java.security.SignatureException e) {
    throw new SignatureException("Unable to calculate signature using RSA PrivateKey. " + e.getMessage(), e);
  }
}
origin: org.apache.sshd/sshd-osgi

public static KeyPair extractEDDSAKeyPair(Buffer buffer, String keyType) throws GeneralSecurityException {
  if (!KeyPairProvider.SSH_ED25519.equals(keyType)) {
    throw new InvalidKeyException("Unsupported key type: " + keyType);
  }
  if (!isEDDSACurveSupported()) {
    throw new NoSuchAlgorithmException(EDDSA + " provider not supported");
  }
  throw new GeneralSecurityException("Full SSHD-440 implementation N/A");
}
origin: wildfly/wildfly

byte[] updateSalt = updateSpec.getSalt();
if (updateSalt != null && ! Arrays.equals(updateSalt, salt)) {
  throw new InvalidAlgorithmParameterException();
  throw new InvalidAlgorithmParameterException();
  addIterations(digest, getMacInstance(algorithm, digest), this.iterationCount, updateIterationCount);
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
  throw new InvalidKeyException(e);
int updateIterationCount = updateSpec.getIterationCount();
if (updateIterationCount < this.iterationCount) {
  throw new InvalidAlgorithmParameterException();
  addIterations(digest, getMacInstance(algorithm, digest), this.iterationCount, updateIterationCount);
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
  throw new InvalidKeyException(e);
origin: wildfly/wildfly

private Signature createSignature(String encodedHeader, String encodedClaims) throws NoSuchAlgorithmException, SignatureException, RealmUnavailableException {
  byte[] headerDecoded = Base64.getUrlDecoder().decode(encodedHeader);
  JsonObject headers = Json.createReader(ByteIterator.ofBytes(headerDecoded).asInputStream()).readObject();
  String headerAlg = resolveAlgorithm(headers);
  Signature signature = Signature.getInstance(headerAlg);
  try {
    PublicKey publicKey = resolvePublicKey(headers);
    if (publicKey == null) {
      log.debug("Public key could not be resolved.");
      return null;
    }
    signature.initVerify(publicKey);
  } catch (InvalidKeyException e) {
    e.printStackTrace();
    return null;
  }
  signature.update((encodedHeader + "." + encodedClaims).getBytes());
  return signature;
}
java.securityInvalidKeyException

Javadoc

InvalidKeyException indicates exceptional conditions, caused by an invalid key.

Most used methods

  • <init>
    Constructs a new instance of InvalidKeyException with the cause.
  • getMessage
  • printStackTrace
  • toString
  • getLocalizedMessage
  • initCause
  • getStackTrace
  • setStackTrace
  • getCause
  • addSuppressed
  • fillInStackTrace
  • fillInStackTrace

Popular in Java

  • Start an intent from android
  • onCreateOptionsMenu (Activity)
  • findViewById (Activity)
  • runOnUiThread (Activity)
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • ZipFile (java.util.zip)
    This class provides random read access to a zip file. You pay more to read the zip file's central di
  • Runner (org.openjdk.jmh.runner)
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now