org.web3j.crypto.CipherException Java Examples
The following examples show how to use
org.web3j.crypto.CipherException.
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: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 6 votes |
private void loadFromJson(Uri uri, String pwd) { sharedManager.setJsonExcep(""); try { ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper(); objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); InputStream is = context.getContentResolver().openInputStream(uri); WalletFile walletFile = objectMapper.readValue(is, WalletFile.class); credentials = Credentials.create(Wallet.decrypt(pwd, walletFile)); } catch (JsonParseException jpe) { sharedManager.setJsonExcep("JsonParseException"); jpe.printStackTrace(); } catch (CipherException ce) { if (ce.getMessage().equals("Invalid password provided")) { sharedManager.setJsonExcep("WrongPassword"); } else { sharedManager.setJsonExcep("CipherException"); } ce.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
Example #2
Source File: OwnWalletUtils.java From Lunary-Ethereum-Wallet with GNU General Public License v3.0 | 6 votes |
public static String generateWalletFile( String password, ECKeyPair ecKeyPair, File destinationDirectory, boolean useFullScrypt) throws CipherException, IOException { WalletFile walletFile; if (useFullScrypt) { walletFile = Wallet.createStandard(password, ecKeyPair); } else { walletFile = Wallet.createLight(password, ecKeyPair); } String fileName = getWalletFileName(walletFile); File destination = new File(destinationDirectory, fileName); ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper(); objectMapper.writeValue(destination, walletFile); return fileName; }
Example #3
Source File: RegisterParamsTest.java From teku with Apache License 2.0 | 6 votes |
@Test void eth1EncryptedKeystoreReturnsCredential(@TempDir final Path tempDir) throws IOException, CipherException { // create v3 wallet final String keystoreFileName = WalletUtils.generateWalletFile(PASSWORD, EXPECTED_EC_KEYPAIR, tempDir.toFile(), true); final File keystoreFile = tempDir.resolve(keystoreFileName).toFile(); // create password file final File passwordFile = Files.writeString(tempDir.resolve("password.txt"), "test123").toFile(); final Eth1PrivateKeyOptions.Eth1EncryptedKeystoreOptions keystoreOptions = new Eth1PrivateKeyOptions.Eth1EncryptedKeystoreOptions(); keystoreOptions.eth1KeystoreFile = keystoreFile; keystoreOptions.eth1KeystorePasswordFile = passwordFile; final Eth1PrivateKeyOptions eth1PrivateKeyOptions = new Eth1PrivateKeyOptions(); eth1PrivateKeyOptions.keystoreOptions = keystoreOptions; final RegisterParams registerParams = new RegisterParams(commandSpec, eth1PrivateKeyOptions, SHUTDOWN_FUNCTION, consoleAdapter); final Credentials eth1Credentials = registerParams.getEth1Credentials(); assertThat(eth1Credentials.getEcKeyPair()).isEqualTo(EXPECTED_EC_KEYPAIR); }
Example #4
Source File: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 6 votes |
private void loadFromJson(Uri uri, String pwd) { sharedManager.setJsonExcep(""); try { ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper(); objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); InputStream is = context.getContentResolver().openInputStream(uri); WalletFile walletFile = objectMapper.readValue(is, WalletFile.class); credentials = Credentials.create(Wallet.decrypt(pwd, walletFile)); } catch (JsonParseException jpe) { sharedManager.setJsonExcep("JsonParseException"); jpe.printStackTrace(); } catch (CipherException ce) { if (ce.getMessage().equals("Invalid password provided")){ sharedManager.setJsonExcep("WrongPassword"); } else { sharedManager.setJsonExcep("CipherException"); } ce.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
Example #5
Source File: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 6 votes |
private void loadFromJson(Uri uri, String pwd) { sharedManager.setJsonExcep(""); try { ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper(); objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); InputStream is = context.getContentResolver().openInputStream(uri); WalletFile walletFile = objectMapper.readValue(is, WalletFile.class); credentials = Credentials.create(Wallet.decrypt(pwd, walletFile)); } catch (JsonParseException jpe) { sharedManager.setJsonExcep("JsonParseException"); jpe.printStackTrace(); } catch (CipherException ce) { if (ce.getMessage().equals("Invalid password provided")) { sharedManager.setJsonExcep("WrongPassword"); } else { sharedManager.setJsonExcep("CipherException"); } ce.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
Example #6
Source File: KeyImporter.java From etherscan-explorer with GNU General Public License v3.0 | 6 votes |
private void createWalletFile(String privateKey) { if (!WalletUtils.isValidPrivateKey(privateKey)) { exitError("Invalid private key specified, must be " + PRIVATE_KEY_LENGTH_IN_HEX + " digit hex value"); } Credentials credentials = Credentials.create(privateKey); String password = getPassword("Please enter a wallet file password: "); String destinationDir = getDestinationDir(); File destination = createDir(destinationDir); try { String walletFileName = WalletUtils.generateWalletFile( password, credentials.getEcKeyPair(), destination, true); console.printf("Wallet file " + walletFileName + " successfully created in: " + destinationDir + "\n"); } catch (CipherException | IOException e) { exitError(e); } }
Example #7
Source File: KeyImporter.java From client-sdk-java with Apache License 2.0 | 6 votes |
private void createWalletFile(String privateKey) { if (!WalletUtils.isValidPrivateKey(privateKey)) { exitError("Invalid private key specified, must be " + PRIVATE_KEY_LENGTH_IN_HEX + " digit hex value"); } Credentials credentials = Credentials.create(privateKey); String password = getPassword("Please enter a wallet file password: "); String destinationDir = getDestinationDir(); File destination = createDir(destinationDir); try { String walletFileName = WalletUtils.generateWalletFile( password, credentials.getEcKeyPair(), destination, true); console.printf("Wallet file " + walletFileName + " successfully created in: " + destinationDir + "\n"); } catch (CipherException | IOException e) { exitError(e); } }
Example #8
Source File: OwnWalletUtils.java From bcm-android with GNU General Public License v3.0 | 6 votes |
public static String generateWalletFile( String password, ECKeyPair ecKeyPair, File destinationDirectory, boolean useFullScrypt) throws CipherException, IOException { WalletFile walletFile; if (useFullScrypt) { walletFile = Wallet.createStandard(password, ecKeyPair); } else { walletFile = Wallet.createLight(password, ecKeyPair); } String fileName = getWalletFileName(walletFile); File destination = new File(destinationDirectory, fileName); ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper(); objectMapper.writeValue(destination, walletFile); return fileName; }
Example #9
Source File: OwnWalletUtils.java From bcm-android with GNU General Public License v3.0 | 5 votes |
public static String generateNewWalletFile( String password, File destinationDirectory, boolean useFullScrypt) throws CipherException, IOException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException { ECKeyPair ecKeyPair = Keys.createEcKeyPair(); return generateWalletFile(password, ecKeyPair, destinationDirectory, useFullScrypt); }
Example #10
Source File: OwnWalletUtils.java From Lunary-Ethereum-Wallet with GNU General Public License v3.0 | 5 votes |
public static String generateNewWalletFile( String password, File destinationDirectory, boolean useFullScrypt) throws CipherException, IOException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException { ECKeyPair ecKeyPair = Keys.createEcKeyPair(); return generateWalletFile(password, ecKeyPair, destinationDirectory, useFullScrypt); }
Example #11
Source File: LWallet.java From dapp-wallet-demo with Apache License 2.0 | 5 votes |
static void validate(WalletFile walletFile) throws CipherException { WalletFile.Crypto crypto = walletFile.getCrypto(); if (walletFile.getVersion() != CURRENT_VERSION) { throw new CipherException("Wallet version is not supported"); } if (!crypto.getCipher().equals(CIPHER)) { throw new CipherException("Wallet cipher is not supported"); } if (!crypto.getKdf().equals(AES_128_CTR) && !crypto.getKdf().equals(SCRYPT)) { throw new CipherException("KDF type is not supported"); } }
Example #12
Source File: LWallet.java From dapp-wallet-demo with Apache License 2.0 | 5 votes |
private static byte[] generateAes128CtrDerivedKey( byte[] password, byte[] salt, int c, String prf) throws CipherException { if (!prf.equals("hmac-sha256")) { throw new CipherException("Unsupported prf:" + prf); } // Java 8 supports this, but you have to convert the password to a character array, see // http://stackoverflow.com/a/27928435/3211687 PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(new SHA256Digest()); gen.init(password, salt, c); return ((KeyParameter) gen.generateDerivedParameters(256)).getKey(); }
Example #13
Source File: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
private WalletFile generateWallet(@NonNull ECKeyPair keyPair, String password) { WalletFile wallet = null; try { wallet = Wallet.createLight(password, keyPair); walletFriendlyAddress = context.getString(R.string.hex_marker) + wallet.getAddress(); walletAddress = wallet.getAddress(); } catch (CipherException e) { e.printStackTrace(); } return wallet; }
Example #14
Source File: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
private WalletFile generateWallet(@NonNull ECKeyPair keyPair, String password) { WalletFile wallet = null; try { wallet = Wallet.createLight(password, keyPair); walletFriendlyAddress = context.getString(R.string.hex_marker) + wallet.getAddress(); walletAddress = wallet.getAddress(); } catch (CipherException e) { e.printStackTrace(); } return wallet; }
Example #15
Source File: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
private void restoreWalletFromFile(String walletPath, String pass, WalletCreationCallback callback) { Credentials credentials = null; try { credentials = WalletUtils.loadCredentials(pass, walletPath); } catch (IOException | CipherException e) { e.printStackTrace(); } if (credentials != null) { ECKeyPair keyPair = credentials.getEcKeyPair(); WalletCreationTask task = new WalletCreationTask(callback, keyPair); task.execute(pass); } }
Example #16
Source File: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
private WalletFile generateWallet(@NonNull ECKeyPair keyPair, String password) { WalletFile wallet = null; try { wallet = Wallet.createLight(password, keyPair); walletFriendlyAddress = context.getString(R.string.hex_marker) + wallet.getAddress(); walletAddress = wallet.getAddress(); } catch (CipherException e) { e.printStackTrace(); } return wallet; }
Example #17
Source File: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
private WalletFile generateWallet(@NonNull ECKeyPair keyPair, String password) { WalletFile wallet = null; try { wallet = Wallet.createLight(password, keyPair); walletFriendlyAddress = context.getString(R.string.hex_marker) + wallet.getAddress(); walletAddress = wallet.getAddress(); } catch (CipherException e) { e.printStackTrace(); } return wallet; }
Example #18
Source File: ProxyIntegrationTest.java From ethsigner with Apache License 2.0 | 5 votes |
@BeforeAll public static void localSetup() { try { setupEthSigner(DEFAULT_CHAIN_ID, ROOT_PATH); } catch (final CipherException | IOException e) { throw new RuntimeException("Failed to setup ethsigner"); } }
Example #19
Source File: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
private void restoreWalletFromFile(String walletPath, String pass, WalletCreationCallback callback) { Credentials credentials = null; try { credentials = WalletUtils.loadCredentials(pass, walletPath); } catch (IOException | CipherException e) { e.printStackTrace(); } if (credentials != null) { ECKeyPair keyPair = credentials.getEcKeyPair(); WalletCreationTask task = new WalletCreationTask(callback, keyPair); task.execute(pass); } }
Example #20
Source File: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
private WalletFile generateWallet(@NonNull ECKeyPair keyPair, String password) { WalletFile wallet = null; try { wallet = Wallet.createLight(password, keyPair); walletFriendlyAddress = context.getString(R.string.hex_marker) + wallet.getAddress(); walletAddress = wallet.getAddress(); } catch (CipherException e) { e.printStackTrace(); } return wallet; }
Example #21
Source File: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
private WalletFile generateWallet(@NonNull ECKeyPair keyPair, String password) { WalletFile wallet = null; try { wallet = Wallet.createLight(password, keyPair); walletFriendlyAddress = context.getString(R.string.hex_marker) + wallet.getAddress(); walletAddress = wallet.getAddress(); } catch (CipherException e) { e.printStackTrace(); } return wallet; }
Example #22
Source File: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
private void restoreWalletFromFile(String walletPath, String pass, WalletCreationCallback callback) { Credentials credentials = null; try { credentials = WalletUtils.loadCredentials(pass, walletPath); } catch (IOException | CipherException e) { e.printStackTrace(); } if (credentials != null) { ECKeyPair keyPair = credentials.getEcKeyPair(); WalletCreationTask task = new WalletCreationTask(callback, keyPair); task.execute(pass); } }
Example #23
Source File: EthQueryExecutor.java From eth-jdbc-connector with Apache License 2.0 | 5 votes |
public Object executeAndReturn() { Insert insert = logicalPlan.getInsert(); String tableName = insert.getChildType(Table.class).get(0).getChildType(IdentifierNode.class, 0).getValue(); if (!EthTables.TRANSACTION.equalsIgnoreCase(tableName)) { throw new BlkchnException("Please give valid table name in insert query. Expected: transaction"); } ColumnName names = insert.getChildType(ColumnName.class).get(0); ColumnValue values = insert.getChildType(ColumnValue.class).get(0); Map<String, String> namesMap = new HashMap<String, String>(); namesMap.put(names.getChildType(IdentifierNode.class, 0).getValue(), values.getChildType(IdentifierNode.class, 0).getValue()); namesMap.put(names.getChildType(IdentifierNode.class, 1).getValue(), values.getChildType(IdentifierNode.class, 1).getValue()); namesMap.put(names.getChildType(IdentifierNode.class, 2).getValue(), values.getChildType(IdentifierNode.class, 2).getValue()); if (names.getChildType(IdentifierNode.class, 3) != null && values.getChildType(IdentifierNode.class, 3) != null) { namesMap.put(names.getChildType(IdentifierNode.class, 3).getValue(), values.getChildType(IdentifierNode.class, 3).getValue()); } boolean async = namesMap.get(ASYNC) == null ? true : Boolean.parseBoolean(namesMap.get(ASYNC)); Object result = null; try { result = insertTransaction(namesMap.get(TO_ADDRESS), namesMap.get(EthColumns.VALUE), namesMap.get(UNIT), !async); } catch (IOException | CipherException | InterruptedException | TransactionException | ExecutionException e) { e.printStackTrace(); throw new BlkchnException("Error while executing query", e); } return result; }
Example #24
Source File: WalletCreator.java From etherscan-explorer with GNU General Public License v3.0 | 5 votes |
private void run() { String password = getPassword("Please enter a wallet file password: "); String destinationDir = getDestinationDir(); File destination = createDir(destinationDir); try { String walletFileName = WalletUtils.generateFullNewWalletFile(password, destination); console.printf("Wallet file " + walletFileName + " successfully created in: " + destinationDir + "\n"); } catch (CipherException | IOException | InvalidAlgorithmParameterException | NoSuchAlgorithmException | NoSuchProviderException e) { Console.exitError(e); } }
Example #25
Source File: EthSignerTestHarnessFactory.java From besu with Apache License 2.0 | 5 votes |
public static EthSignerTestHarness create( final Path tempDir, final String keyPath, final Integer besuPort, final long chainId) throws IOException, CipherException { final Path keyFilePath = copyResource(keyPath, tempDir.resolve(keyPath)); final EthSignerConfig config = new EthSignerConfig( Level.DEBUG, HOST, besuPort, Duration.ofSeconds(10), HOST, 0, new ConfigurationChainId(chainId), tempDir); final EthSigner ethSigner = new EthSigner( config, new SingleTransactionSignerProvider( new CredentialTransactionSigner( WalletUtils.loadCredentials("", keyFilePath.toAbsolutePath().toFile())))); ethSigner.run(); waitForPortFile(tempDir); LOG.info("EthSigner port: {}", config.getHttpListenPort()); return new EthSignerTestHarness(config, loadPortsFile(tempDir)); }
Example #26
Source File: WalletUpdater.java From etherscan-explorer with GNU General Public License v3.0 | 5 votes |
private void run(String walletFileLocation) { File walletFile = new File(walletFileLocation); Credentials credentials = getCredentials(walletFile); console.printf("Wallet for address " + credentials.getAddress() + " loaded\n"); String newPassword = getPassword("Please enter a new wallet file password: "); String destinationDir = getDestinationDir(); File destination = createDir(destinationDir); try { String walletFileName = WalletUtils.generateWalletFile( newPassword, credentials.getEcKeyPair(), destination, true); console.printf("New wallet file " + walletFileName + " successfully created in: " + destinationDir + "\n"); } catch (CipherException | IOException e) { exitError(e); } String delete = console.readLine( "Would you like to delete your existing wallet file (Y/N)? [N]: "); if (delete.toUpperCase().equals("Y")) { if (!walletFile.delete()) { exitError("Unable to remove wallet file\n"); } else { console.printf("Deleted previous wallet file: %s\n", walletFile.getName()); } } }
Example #27
Source File: ImportPrivateKey.java From ETHWallet with GNU General Public License v3.0 | 5 votes |
@Test public void privateKeyToKeystoreTest() throws UnsupportedEncodingException, CipherException, JsonProcessingException { String privateKey = "68adf89afe85baa046919f904f7c1e3a9cb28ca8b3039c2bcb3fa5a980d3a165"; String passphrase = "x"; WalletFile w = EtherStoreUtils.convertPrivateKeyToKeystoreFile(privateKey, passphrase); assert(w.getAddress().equals("7d788fc8df7165b11a19f201558fcc3590fd8d97")); }
Example #28
Source File: WalletCreator.java From client-sdk-java with Apache License 2.0 | 5 votes |
private void run() { String password = getPassword("Please enter a wallet file password: "); String destinationDir = getDestinationDir(); File destination = createDir(destinationDir); try { String walletFileName = WalletUtils.generateFullNewWalletFile(password, destination); console.printf("Wallet file " + walletFileName + " successfully created in: " + destinationDir + "\n"); } catch (CipherException | IOException | InvalidAlgorithmParameterException | NoSuchAlgorithmException | NoSuchProviderException e) { Console.exitError(e); } }
Example #29
Source File: WalletUpdater.java From client-sdk-java with Apache License 2.0 | 5 votes |
private void run(String walletFileLocation) { File walletFile = new File(walletFileLocation); Credentials credentials = getCredentials(walletFile); console.printf("Wallet for address " + credentials.getAddress() + " loaded\n"); String newPassword = getPassword("Please enter a new wallet file password: "); String destinationDir = getDestinationDir(); File destination = createDir(destinationDir); try { String walletFileName = WalletUtils.generateWalletFile( newPassword, credentials.getEcKeyPair(), destination, true); console.printf("New wallet file " + walletFileName + " successfully created in: " + destinationDir + "\n"); } catch (CipherException | IOException e) { exitError(e); } String delete = console.readLine( "Would you like to delete your existing wallet file (Y/N)? [N]: "); if (delete.toUpperCase().equals("Y")) { if (!walletFile.delete()) { exitError("Unable to remove wallet file\n"); } else { console.printf("Deleted previous wallet file: %s\n", walletFile.getName()); } } }
Example #30
Source File: IntegrationTestBase.java From ethsigner with Apache License 2.0 | 4 votes |
static void setupEthSigner(final long chainId, final String downstreamHttpRequestPath) throws IOException, CipherException { clientAndServer = startClientAndServer(); final File keyFile = createKeyFile(); final File passwordFile = createFile("password"); credentials = WalletUtils.loadCredentials("password", keyFile); final TransactionSignerProvider transactionSignerProvider = new SingleTransactionSignerProvider(transactionSigner(keyFile, passwordFile)); final HttpClientOptions httpClientOptions = new HttpClientOptions(); httpClientOptions.setDefaultHost(LOCALHOST); httpClientOptions.setDefaultPort(clientAndServer.getLocalPort()); final HttpServerOptions httpServerOptions = new HttpServerOptions(); httpServerOptions.setPort(0); httpServerOptions.setHost("localhost"); // Force TransactionDeserialisation to fail final ObjectMapper jsonObjectMapper = new ObjectMapper(); jsonObjectMapper.configure(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES, true); jsonObjectMapper.configure(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES, true); final JsonDecoder jsonDecoder = new JsonDecoder(jsonObjectMapper); vertx = Vertx.vertx(); runner = new Runner( chainId, transactionSignerProvider, httpClientOptions, httpServerOptions, downstreamTimeout, new DownstreamPathCalculator(downstreamHttpRequestPath), jsonDecoder, dataPath, vertx, singletonList("sample.com")); runner.start(); final Path portsFile = dataPath.resolve(PORTS_FILENAME); waitForNonEmptyFileToExist(portsFile); final int ethSignerPort = httpJsonRpcPort(portsFile); RestAssured.port = ethSignerPort; LOG.info( "Started ethSigner on port {}, eth stub node on port {}", ethSignerPort, clientAndServer.getLocalPort()); unlockedAccount = transactionSignerProvider.availableAddresses().stream().findAny().orElseThrow(); }