@Override protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException { AlgorithmParameterSpec spec; try { spec = params.getParameterSpec(IvParameterSpec.class); if (debug.DEBUG) log("initialized with key and AlgorithmParameters"); } catch (InvalidParameterSpecException ipe) { throw new InvalidAlgorithmParameterException(ipe); } wolfCryptCipherInit(opmode, key, spec, random); }
protected void engineInit(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException { if (!(paramSpec instanceof RC2ParameterSpec)) { throw new InvalidParameterSpecException ("Inappropriate parameter specification"); } RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec; // check effective key size (a value of 0 means it is unspecified) effectiveKeySize = rps.getEffectiveKeyBits(); if (effectiveKeySize != 0) { if (effectiveKeySize < 1 || effectiveKeySize > 1024) { throw new InvalidParameterSpecException("RC2 effective key " + "size must be between 1 and 1024 bits"); } if (effectiveKeySize < 256) { version = EKB_TABLE[effectiveKeySize]; } else { version = effectiveKeySize; } } this.iv = rps.getIV(); }
protected AlgorithmParameterSpec localEngineGetParameterSpec( Class paramSpec) throws InvalidParameterSpecException { if (paramSpec == RC2ParameterSpec.class) { if (parameterVersion != -1) { if (parameterVersion < 256) { return new RC2ParameterSpec(ekb[parameterVersion], iv); } else { return new RC2ParameterSpec(parameterVersion, iv); } } } if (paramSpec == IvParameterSpec.class) { return new IvParameterSpec(iv); } throw new InvalidParameterSpecException("unknown parameter spec passed to RC2 parameters object."); }
/** * Returns the DSA parameters associated with this key, or null if the * parameters could not be parsed. */ public DSAParams getParams() { try { if (algid instanceof DSAParams) { return (DSAParams)algid; } else { DSAParameterSpec paramSpec; AlgorithmParameters algParams = algid.getParameters(); if (algParams == null) { return null; } paramSpec = algParams.getParameterSpec(DSAParameterSpec.class); return (DSAParams)paramSpec; } } catch (InvalidParameterSpecException e) { return null; } }
protected <T extends AlgorithmParameterSpec> T engineGetParameterSpec(Class<T> paramSpec) throws InvalidParameterSpecException { try { Class<?> dsaParamSpec = Class.forName ("java.security.spec.DSAParameterSpec"); if (dsaParamSpec.isAssignableFrom(paramSpec)) { return paramSpec.cast( new DSAParameterSpec(this.p, this.q, this.g)); } else { throw new InvalidParameterSpecException ("Inappropriate parameter Specification"); } } catch (ClassNotFoundException e) { throw new InvalidParameterSpecException ("Unsupported parameter specification: " + e.getMessage()); } }
protected void engineInit( AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException { if (!(paramSpec instanceof ElGamalParameterSpec) && !(paramSpec instanceof DHParameterSpec)) { throw new InvalidParameterSpecException("DHParameterSpec required to initialise a ElGamal algorithm parameters object"); } if (paramSpec instanceof ElGamalParameterSpec) { this.currentSpec = (ElGamalParameterSpec)paramSpec; } else { DHParameterSpec s = (DHParameterSpec)paramSpec; this.currentSpec = new ElGamalParameterSpec(s.getP(), s.getG()); } }
protected AlgorithmParameters engineGetParameters() { if (spec != null && spec instanceof OAEPParameterSpec) { try { AlgorithmParameters params = AlgorithmParameters.getInstance("OAEP", SunJCE.getInstance()); params.init(spec); return params; } catch (NoSuchAlgorithmException nsae) { // should never happen throw new RuntimeException("Cannot find OAEP " + " AlgorithmParameters implementation in SunJCE provider"); } catch (InvalidParameterSpecException ipse) { // should never happen throw new RuntimeException("OAEPParameterSpec not supported"); } } else { return null; } }
protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException { if (params == null) { init(opmode, key, random, null); } else { try { OAEPParameterSpec spec = params.getParameterSpec(OAEPParameterSpec.class); init(opmode, key, random, spec); } catch (InvalidParameterSpecException ipse) { InvalidAlgorithmParameterException iape = new InvalidAlgorithmParameterException("Wrong parameter"); iape.initCause(ipse); throw iape; } } }
private void checkCryptoPerm(CipherSpi checkSpi, Key key, AlgorithmParameters params) throws InvalidKeyException, InvalidAlgorithmParameterException { if (cryptoPerm == CryptoAllPermission.INSTANCE) { return; } // Convert the specified parameters into specs and then delegate. AlgorithmParameterSpec pSpec; try { pSpec = getAlgorithmParameterSpec(params); } catch (InvalidParameterSpecException ipse) { throw new InvalidAlgorithmParameterException ("Failed to retrieve algorithm parameter specification"); } checkCryptoPerm(checkSpi, key, pSpec); }
/** * Methods used to write the current ClientWallent into a generated file. * @param userPassword * @param accountName * @param keyPair * @throws InvalidKeyException * @throws InvalidParameterSpecException * @throws IllegalBlockSizeException * @throws BadPaddingException * @throws FileNotFoundException * @throws IOException */ public static void writeWalletFile(final char[] userPassword, final String accountName, final KeyPair keyPair) throws InvalidKeyException, InvalidParameterSpecException, IllegalBlockSizeException, BadPaddingException, FileNotFoundException, IOException { // Write wallet information in the wallet file final WalletInformation walletInformation = Cryptography.walletInformationFromKeyPair(userPassword, keyPair); // Creates wallet folder if not exists final File walletFolder = new File(Parameters.WALLETS_PATH); if (!walletFolder.exists()) { walletFolder.mkdir(); } // Creates new wallet file final File f = new File(Parameters.WALLETS_PATH + accountName + ".wallet"); final ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f)); oos.writeObject(walletInformation); oos.flush(); oos.close(); System.out.println("The creation of your wallet completed successfully"); System.out.println("Please sign in and start crashing coins"); }
private void actionMenuNotRegistered(final int choice) throws ClassNotFoundException, IOException, FileNotFoundException, InvalidKeyException, InvalidAlgorithmParameterException, InvalidKeySpecException, IllegalBlockSizeException, BadPaddingException, InvalidParameterSpecException { switch (choice) { case 1: signIn(); break; case 2: signUp(); break; case 3: // close with condition in while break; default: System.out.println("Unknow choice " + choice + "\n"); break; } }
public static void main(final String[] argv) throws IOException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, InvalidParameterSpecException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, ClassNotFoundException, GeneralSecurityException { if(argv.length >= 2) { ip = argv[0]; port = Integer.parseInt(argv[1]); } else { Logger.getLogger(Main.class.getName()).log(Level.INFO, "Default ip and port were applied."); ip = Parameters.RELAY_IP; port = Parameters.RELAY_PORT_WALLET_LISTENER; } // Init connection with relay try { RelayConnection.getInstance(); } catch(IOException ex) { Logger.getLogger(Main.class.getName()).severe(ex.getMessage()); return; } new ClientApplication(); }
@Override protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException { try { engineInit(opmode, key, params.getParameterSpec(AlgorithmParameterSpec.class), random); } catch (InvalidParameterSpecException e) { throw new InvalidAlgorithmParameterException(e); } }
protected <T extends AlgorithmParameterSpec> T engineGetParameterSpec(Class<T> paramSpec) throws InvalidParameterSpecException { if (GCMParameterSpec.class.isAssignableFrom(paramSpec)) { return paramSpec.cast(new GCMParameterSpec(tLen * 8, iv)); } else { throw new InvalidParameterSpecException ("Inappropriate parameter specification"); } }
protected void engineInit( AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException { if (!(paramSpec instanceof PBEParameterSpec)) { throw new InvalidParameterSpecException("PBEParameterSpec required to initialise a PKCS12 PBE parameters algorithm parameters object"); } PBEParameterSpec pbeSpec = (PBEParameterSpec)paramSpec; this.params = new PKCS12PBEParams(pbeSpec.getSalt(), pbeSpec.getIterationCount()); }
void init(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException { if (!(paramSpec instanceof IvParameterSpec)) { throw new InvalidParameterSpecException ("Inappropriate parameter specification"); } byte[] tmpIv = ((IvParameterSpec)paramSpec).getIV(); if (tmpIv.length != block_size) { throw new InvalidParameterSpecException("IV not " + block_size + " bytes long"); } iv = tmpIv.clone(); }
protected void engineInit( AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException { if (!(paramSpec instanceof PBEParameterSpec)) { throw new InvalidParameterSpecException("PBEParameterSpec required to initialise a PBKDF2 PBE parameters algorithm parameters object"); } PBEParameterSpec pbeSpec = (PBEParameterSpec)paramSpec; this.params = new PBKDF2Params(pbeSpec.getSalt(), pbeSpec.getIterationCount()); }
protected AlgorithmParameterSpec localEngineGetParameterSpec( Class paramSpec) throws InvalidParameterSpecException { if (paramSpec == IvParameterSpec.class) { return new IvParameterSpec(iv); } throw new InvalidParameterSpecException("unknown parameter spec passed to CAST5 parameters object."); }
protected AlgorithmParameterSpec localEngineGetParameterSpec( Class paramSpec) throws InvalidParameterSpecException { if (paramSpec == IvParameterSpec.class) { return new IvParameterSpec(iv); } throw new InvalidParameterSpecException("unknown parameter spec passed to IV parameters object."); }
protected void engineInit( AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException { if (!(paramSpec instanceof IvParameterSpec)) { throw new InvalidParameterSpecException("IvParameterSpec required to initialise a IV parameters algorithm parameters object"); } this.iv = ((IvParameterSpec)paramSpec).getIV(); }
protected AlgorithmParameterSpec engineGetParameterSpec( Class paramSpec) throws InvalidParameterSpecException { if (paramSpec == null) { throw new NullPointerException("argument to getParameterSpec must not be null"); } return localEngineGetParameterSpec(paramSpec); }
protected void engineInit(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException { if (!(paramSpec instanceof PBEParameterSpec)) { throw new InvalidParameterSpecException ("Inappropriate parameter specification"); } this.salt = ((PBEParameterSpec)paramSpec).getSalt().clone(); this.iCount = ((PBEParameterSpec)paramSpec).getIterationCount(); this.cipherParam = ((PBEParameterSpec)paramSpec).getParameterSpec(); }
protected void engineInit(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException { if (!(paramSpec instanceof GCMParameterSpec)) { throw new InvalidParameterSpecException ("Inappropriate parameter specification"); } GCMParameterSpec gps = (GCMParameterSpec) paramSpec; // need to convert from bits to bytes for ASN.1 encoding this.tLen = gps.getTLen()/8; this.iv = gps.getIV(); }
static ECGenParameterSpec getECGenParamSpec(NamedGroup namedGroup) { if (namedGroup.type != NamedGroupType.NAMED_GROUP_ECDHE) { throw new RuntimeException("Not a named EC group: " + namedGroup); } AlgorithmParameters params = namedGroupParams.get(namedGroup); try { return params.getParameterSpec(ECGenParameterSpec.class); } catch (InvalidParameterSpecException ipse) { // should be unlikely return new ECGenParameterSpec(namedGroup.oid); } }
@Override protected void initCipher(int mode) throws InvalidKeyException, InvalidAlgorithmParameterException, InvalidParameterSpecException { if (Cipher.ENCRYPT_MODE == mode) { ci.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key.getEncoded(), KEY_ALGORITHM)); iv = ci.getParameters().getParameterSpec(IvParameterSpec.class) .getIV(); } else { ci.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key.getEncoded(), KEY_ALGORITHM), new IvParameterSpec(iv)); } }
protected AlgorithmParameterSpec localEngineGetParameterSpec( Class paramSpec) throws InvalidParameterSpecException { if (paramSpec == DHParameterSpec.class) { return currentSpec; } throw new InvalidParameterSpecException("unknown parameter spec passed to DH parameters object."); }
protected void engineInit( AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException { if (!(paramSpec instanceof DHParameterSpec)) { throw new InvalidParameterSpecException("DHParameterSpec required to initialise a Diffie-Hellman algorithm parameters object"); } this.currentSpec = (DHParameterSpec)paramSpec; }
protected AlgorithmParameterSpec localEngineGetParameterSpec( Class paramSpec) throws InvalidParameterSpecException { if (paramSpec == OAEPParameterSpec.class && currentSpec != null) { return currentSpec; } throw new InvalidParameterSpecException("unknown parameter spec passed to OAEP parameters object."); }
protected AlgorithmParameterSpec localEngineGetParameterSpec( Class paramSpec) throws InvalidParameterSpecException { if (paramSpec == PSSParameterSpec.class && currentSpec != null) { return currentSpec; } throw new InvalidParameterSpecException("unknown parameter spec passed to PSS parameters object."); }