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

The following examples show how to use java.security.InvalidKeyException#printStackTrace() . 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 File: ITSUtils.java    From signature with MIT License 6 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 File: PKCS8Key.java    From openjdk-jdk9 with 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 3
Source File: X509Key.java    From Bytecoder with 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());
    }
}
 
Example 4
Source File: PKCS8Key.java    From openjdk-jdk8u-backup with 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 5
Source File: X509Key.java    From openjdk-jdk8u-backup with 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 6
Source File: PluggableParameterOperatorBinary.java    From mts with GNU General Public License v3.0 5 votes vote down vote up
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 7
Source File: PKCS8Key.java    From openjdk-jdk8u with 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 8
Source File: X509Key.java    From openjdk-jdk8u with 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 9
Source File: HmacSha512.java    From BlockchainWallet-Crypto with GNU General Public License v3.0 5 votes vote down vote up
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 10
Source File: RsaImpl.java    From julongchain with 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 11
Source File: HMACBench.java    From bumblebench with 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 12
Source File: PKCS8Key.java    From Bytecoder with 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 13
Source File: PKCS8Key.java    From jdk8u60 with 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 14
Source File: X509Key.java    From jdk8u60 with 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 15
Source File: PKCS8Key.java    From TencentKona-8 with 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 16
Source File: X509Key.java    From openjdk-jdk9 with 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 17
Source File: PKCS8Key.java    From dragonwell8_jdk with 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 18
Source File: PKCS8Key.java    From jdk8u-jdk with 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 19
Source File: ContactAdapter.java    From VyAPI with 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 20
Source File: CommonUtil.java    From GOAi with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}