Java Code Examples for java.security.InvalidKeyException#printStackTrace()

The following examples show how to use java.security.InvalidKeyException#printStackTrace() . These examples are extracted from open source projects. 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 Project: signature   File: ITSUtils.java    License: MIT License 7 votes vote down vote up
/**
 * create by: iizvv
 * description: 获取Token
 * create time: 2019-06-29 15:14
 *

 * @return 请求头
 */
static Map getToken(String p8, String iss, String kid) {
    String s = p8.
            replace("-----BEGIN PRIVATE KEY-----", "").
            replace("-----END PRIVATE KEY-----", "");
    byte[] encodeKey = Base64.decode(s);
    String token = null;
    try {
        token = Jwts.builder().
                setHeaderParam(JwsHeader.ALGORITHM, "ES256").
                setHeaderParam(JwsHeader.KEY_ID,kid).
                setHeaderParam(JwsHeader.TYPE, "JWT").

                setIssuer(iss).
                claim("exp", System.currentTimeMillis()/1000 +  60 * 10).
                setAudience("appstoreconnect-v1").
                signWith(SignatureAlgorithm.ES256, new ECPrivateKeyImpl(encodeKey)).
                compact();
    } catch (InvalidKeyException e) {
        e.printStackTrace();
    }
    Map map = new HashMap();
    map.put("Content-Type", "application/json");
    map.put("Authorization", "Bearer " + token);
    return map;
}
 
Example 2
Source Project: Bytecoder   File: PKCS8Key.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Serialization read ... PKCS#8 keys serialize as
 * themselves, and they're parsed when they get read back.
 */
@java.io.Serial
private void readObject (ObjectInputStream stream)
throws IOException {

    try {
        decode(stream);

    } catch (InvalidKeyException e) {
        e.printStackTrace();
        throw new IOException("deserialized key is invalid: " +
                              e.getMessage());
    }
}
 
Example 3
/**
 * hmac HmacSHA256
 *
 * @param message 信息
 * @param secret  秘钥
 * @return 加密结果
 */
public static String hmacSha256(String message, String secret) {
    Exception exception = null;
    try {
        Mac mac = Mac.getInstance("HmacSHA256");
        SecretKeySpec secretKeySpec = new SecretKeySpec(secret.getBytes(), "HmacSHA256");
        mac.init(secretKeySpec);
        return HexUtil.hexEncode(mac.doFinal(message.getBytes()), false);
    } catch (NoSuchAlgorithmException ignored) {
    } catch (InvalidKeyException e) {
        e.printStackTrace();
        exception = e;
    }
    throw new ExchangeException("hmacSha256 error.", exception);
}
 
Example 4
Source Project: VyAPI   File: ContactAdapter.java    License: MIT License 5 votes vote down vote up
@Override
public void onBindViewHolder(@NonNull ContactHolder holder, final int position) {
    Contact currentContact = contacts.get(position);
    holder.tvName.setText(currentContact.getFname() + " " + currentContact.getLname());
    holder.tvWebsite.setText(currentContact.getWebsite());

    holder.tvName.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            index = position;
            notifyDataSetChanged();
        }
    });

    if(index == position){
        HomeFragment.selected_id = currentContact.getId();
        HomeFragment.selected_fname = currentContact.getFname();
        HomeFragment.selected_lname = currentContact.getLname();
        try {
            HomeFragment.selected_phonenumber = CreateContactFragment.decrypt(currentContact.getPhonenumber());
            HomeFragment.selected_email = CreateContactFragment.decrypt(currentContact.getEmail());
        } catch (InvalidKeyException e) {
            e.printStackTrace();
        }
        HomeFragment.selected_website = currentContact.getWebsite();
        HomeFragment.selected_location = currentContact.getLocation();

        holder.tvName.setTextColor(Color.parseColor("#0033cc"));
    }else {
        holder.tvName.setTextColor(Color.parseColor("#000000"));
    }
}
 
Example 5
Source Project: jdk8u-jdk   File: PKCS8Key.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Serialization read ... PKCS#8 keys serialize as
 * themselves, and they're parsed when they get read back.
 */
private void readObject (ObjectInputStream stream)
throws IOException {

    try {
        decode(stream);

    } catch (InvalidKeyException e) {
        e.printStackTrace();
        throw new IOException("deserialized key is invalid: " +
                              e.getMessage());
    }
}
 
Example 6
/**
 * Serialization read ... PKCS#8 keys serialize as
 * themselves, and they're parsed when they get read back.
 */
private void readObject (ObjectInputStream stream)
throws IOException {

    try {
        decode(stream);

    } catch (InvalidKeyException e) {
        e.printStackTrace();
        throw new IOException("deserialized key is invalid: " +
                              e.getMessage());
    }
}
 
Example 7
/**
 * Serialization read ... X.509 keys serialize as
 * themselves, and they're parsed when they get read back.
 */
private void readObject(ObjectInputStream stream) throws IOException {
    try {
        decode(stream);
    } catch (InvalidKeyException e) {
        e.printStackTrace();
        throw new IOException("deserialized key is invalid: " +
                              e.getMessage());
    }
}
 
Example 8
/**
 * Serialization read ... PKCS#8 keys serialize as
 * themselves, and they're parsed when they get read back.
 */
private void readObject (ObjectInputStream stream)
throws IOException {

    try {
        decode(stream);

    } catch (InvalidKeyException e) {
        e.printStackTrace();
        throw new IOException("deserialized key is invalid: " +
                              e.getMessage());
    }
}
 
Example 9
Source Project: jdk8u60   File: X509Key.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Serialization read ... X.509 keys serialize as
 * themselves, and they're parsed when they get read back.
 */
private void readObject(ObjectInputStream stream) throws IOException {
    try {
        decode(stream);
    } catch (InvalidKeyException e) {
        e.printStackTrace();
        throw new IOException("deserialized key is invalid: " +
                              e.getMessage());
    }
}
 
Example 10
Source Project: jdk8u60   File: PKCS8Key.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Serialization read ... PKCS#8 keys serialize as
 * themselves, and they're parsed when they get read back.
 */
private void readObject (ObjectInputStream stream)
throws IOException {

    try {
        decode(stream);

    } catch (InvalidKeyException e) {
        e.printStackTrace();
        throw new IOException("deserialized key is invalid: " +
                              e.getMessage());
    }
}
 
Example 11
/**
 * Serialization read ... PKCS#8 keys serialize as
 * themselves, and they're parsed when they get read back.
 */
private void readObject (ObjectInputStream stream)
throws IOException {

    try {
        decode(stream);

    } catch (InvalidKeyException e) {
        e.printStackTrace();
        throw new IOException("deserialized key is invalid: " +
                              e.getMessage());
    }
}
 
Example 12
Source Project: bumblebench   File: HMACBench.java    License: Apache License 2.0 5 votes vote down vote up
protected long doBatch(long numBytes) throws InterruptedException {
    long numIterations = java.lang.Math.round((double)numBytes/data.length);
    try{
        for (long i = 0; i < numIterations; i++) {
            mac.init(key);
            byte[] result = mac.doFinal(data);
        }
    } catch (InvalidKeyException e){
        e.printStackTrace();
    }
    return numIterations*data.length;
}
 
Example 13
Source Project: julongchain   File: RsaImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取ASN.1 格式公钥编码
 * @param n     N
 * @param e     E
 * @return 公钥编码
 * @throws CspException
 */
private static byte[] getPublicDer(BigInteger n, BigInteger e) throws CspException{
    try {
        RSAPublicKeyImpl rsapublickeyimpl = new RSAPublicKeyImpl(n, e);
        return rsapublickeyimpl.getEncoded();
    }catch( InvalidKeyException ex){
        ex.printStackTrace();
        String err = String.format("[JC_PKCS]:InvalidKeyException ErrMessage: %s", ex.getMessage());
        setLoggerErr(err, 0);
        throw new CspException(err, ex.getCause());
    }
}
 
Example 14
private static Mac initialize(final byte[] byteKey) {
    final Mac hmacSha512 = getInstance(HMAC_SHA512);
    final SecretKeySpec keySpec = new SecretKeySpec(byteKey, HMAC_SHA512);
    try {
        hmacSha512.init(keySpec);
    } catch (InvalidKeyException e) {
        e.printStackTrace();
    }
    return hmacSha512;
}
 
Example 15
/**
 * Serialization read ... X.509 keys serialize as
 * themselves, and they're parsed when they get read back.
 */
private void readObject(ObjectInputStream stream) throws IOException {
    try {
        decode(stream);
    } catch (InvalidKeyException e) {
        e.printStackTrace();
        throw new IOException("deserialized key is invalid: " +
                              e.getMessage());
    }
}
 
Example 16
/**
 * Serialization read ... PKCS#8 keys serialize as
 * themselves, and they're parsed when they get read back.
 */
private void readObject (ObjectInputStream stream)
throws IOException {

    try {
        decode(stream);

    } catch (InvalidKeyException e) {
        e.printStackTrace();
        throw new IOException("deserialized key is invalid: " +
                              e.getMessage());
    }
}
 
Example 17
private static byte[][] deriveSRTPKeys(Cipher AEScipher, long index, long keyDerivationRate, byte[] masterSalt, byte[] masterKey) throws UnsupportedEncodingException
{
	byte[] iv = new byte[16];
	byte[] encKey = new byte[16];
	byte[] authKey = new byte[20];
	byte[] saltKey = new byte[14];
	byte[][] ret = new byte[3][];
	long label = 0;

    // compute the session encryption key
    computeIv(iv, label, index, keyDerivationRate, masterSalt);
    SecretKey encryptionKey = new SecretKeySpec(masterKey, 0, 16, "AES");
    
    try 
    {
        AEScipher.init(Cipher.ENCRYPT_MODE, encryptionKey);
    } 
    catch (InvalidKeyException e1) 
    {
        e1.printStackTrace();
    }
    
    getCipherStream(AEScipher, encKey, 16, iv);
    
    label = 0x01;
    computeIv(iv, label, index, keyDerivationRate, masterSalt);
    getCipherStream(AEScipher, authKey, 20, iv);

    label = 0x02;
    computeIv(iv, label, index, keyDerivationRate, masterSalt);
    getCipherStream(AEScipher, saltKey, 14, iv);       
    ret[0] = encKey;
    ret[1] = authKey;
    ret[2] = saltKey;
    return ret;
}
 
Example 18
/**
 * Serialization read ... X.509 keys serialize as
 * themselves, and they're parsed when they get read back.
 */
private void readObject(ObjectInputStream stream) throws IOException {
    try {
        decode(stream);
    } catch (InvalidKeyException e) {
        e.printStackTrace();
        throw new IOException("deserialized key is invalid: " +
                              e.getMessage());
    }
}
 
Example 19
/**
 * Serialization read ... PKCS#8 keys serialize as
 * themselves, and they're parsed when they get read back.
 */
private void readObject (ObjectInputStream stream)
throws IOException {

    try {
        decode(stream);

    } catch (InvalidKeyException e) {
        e.printStackTrace();
        throw new IOException("deserialized key is invalid: " +
                              e.getMessage());
    }
}
 
Example 20
Source Project: Bytecoder   File: X509Key.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Serialization read ... X.509 keys serialize as
 * themselves, and they're parsed when they get read back.
 */
@java.io.Serial
private void readObject(ObjectInputStream stream) throws IOException {
    try {
        decode(stream);
    } catch (InvalidKeyException e) {
        e.printStackTrace();
        throw new IOException("deserialized key is invalid: " +
                              e.getMessage());
    }
}