@Test
  public void testStoringSecretKeys() throws IOException {
    final AesCipherService cipherService = new AesCipherService();
    cipherService.setKeySize(AESKeySizes.KEY_SIZE_256);

    final Key key = cipherService.generateNewKey();
    final byte[] keyBytes = SerializationUtils.serialize(key);
    final ByteString keyByteString = ByteString.copyFrom(keyBytes);

    final String keyName = "GLOBAL";
    final SecretKeys keys =
        SecretKeys.newBuilder().putAllKeys(ImmutableMap.of(keyName, keyByteString)).build();

    final EncryptionService service1 = new EncryptionServiceImpl(cipherService, toKeyMap(keys));

    final byte[] encryptedData = service1.encrypt("data".getBytes(), keyName);
    assertThat("data", is(new String(service1.decrypt(encryptedData, keyName))));

    final File secretKeysFile = new File("build/temp/secretKeys");
    secretKeysFile.getParentFile().mkdirs();
    try (final OutputStream os = new FileOutputStream(secretKeysFile)) {
      keys.writeTo(os);
    }

    final AesCipherService cipherService2 = new AesCipherService();
    cipherService2.setKeySize(AESKeySizes.KEY_SIZE_256);
    try (final InputStream is = new FileInputStream(secretKeysFile)) {
      final EncryptionService service2 =
          new EncryptionServiceImpl(cipherService2, toKeyMap(SecretKeys.parseFrom(is)));
      assertThat("data", is(new String(service2.decrypt(encryptedData, keyName))));
    }
  }
 private void updateReviewDataInternal(Serializable results) {
   String selection = MovieContract.MovieEntry.COLUMN_MOVIE_ID + "=?";
   String[] selectionArgs = new String[] {mMovieId.toString()};
   ContentValues cv = new ContentValues();
   cv.put(MovieContract.MovieEntry.COLUMN_MOVIE_REVIEWS, SerializationUtils.serialize(results));
   getActivity()
       .getContentResolver()
       .update(MovieContract.MovieEntry.buildUriReviews(mMovieId), cv, selection, selectionArgs);
 }
示例#3
0
文件: Handle.java 项目: rikw22/SPFBL
 /** Armazenamento de cache em disco. */
 public static synchronized void store() {
   if (HANDLE_CHANGED) {
     try {
       Server.logDebug("Storing handle.map...");
       FileOutputStream outputStream = new FileOutputStream("handle.map");
       try {
         SerializationUtils.serialize(HANDLE_MAP, outputStream);
         // Atualiza flag de atualização.
         HANDLE_CHANGED = false;
       } finally {
         outputStream.close();
       }
     } catch (Exception ex) {
       Server.logError(ex);
     }
   }
 }
 private void sendDataTcp(int dataServerPort, String xmlEmployees) throws IOException {
   ServerSocket serverSocket = new ServerSocket(dataServerPort);
   serverSocket.setSoTimeout((int) SECONDS.toMillis(100));
   boolean isTimeExpired = false;
   while (!isTimeExpired) {
     try {
       Socket socket = serverSocket.accept(); // Blocking call!
       serialize(xmlEmployees, socket.getOutputStream());
       socket.close();
     } catch (SocketTimeoutException e) {
       System.out.println(
           "[WARNING] ----------------------------------------- \n"
               + "[WARNING] Waiting time expired... Socket is closed.");
       isTimeExpired = true;
       continue;
     }
   }
   serverSocket.close();
 }
示例#5
0
 /** Armazenamento de cache em disco. */
 public static synchronized void store() {
   if (OWNER_CHANGED) {
     try {
       long time = System.currentTimeMillis();
       File file = new File("owner.map");
       FileOutputStream outputStream = new FileOutputStream(file);
       try {
         SerializationUtils.serialize(OWNER_MAP, outputStream);
         // Atualiza flag de atualização.
         OWNER_CHANGED = false;
       } finally {
         outputStream.close();
       }
       Server.logStore(time, file);
     } catch (Exception ex) {
       Server.logError(ex);
     }
   }
 }
示例#6
0
文件: Owner.java 项目: Brusca/SPFBL
 /** Armazenamento de cache em disco. */
 public static void store() {
   if (OWNER_CHANGED) {
     try {
       long time = System.currentTimeMillis();
       HashMap<String, Owner> map = getMap();
       File file = new File("./data/owner.map");
       FileOutputStream outputStream = new FileOutputStream(file);
       try {
         SerializationUtils.serialize(map, outputStream);
         // Atualiza flag de atualização.
         OWNER_CHANGED = false;
       } finally {
         outputStream.close();
       }
       Server.logStore(time, file);
     } catch (Exception ex) {
       Server.logError(ex);
     }
   }
 }
 public byte[] serialise(final Serializable o) {
   return org.apache.commons.lang3.SerializationUtils.serialize(o);
 }
  @Test
  public void shouldBeSerializable() {
    Denomination denomination = new Denomination("foo", "bar", "fuz", "buz");
    Destination destination =
        new Destination(
            "fizbiz", "foobar", "biz", "foobiz", "foobuz", "fizbuz", "fizbiz", "foo", "bar", "fiz",
            "biz", "buz");
    Fee fee = new Fee("foo", "bar", "fuz", "buz", "biz");
    List<Fee> fees = new ArrayList<>();
    List<Normalized> normalizeds = new ArrayList<>();
    List<Source> sources = new ArrayList<>();
    Origin origin =
        new Origin(
            "biz", "foo", "fiz", "bar", "foobar", "foobiz", "fiz", "biz", "fuzbuz", "fuz", sources,
            "buz", "FOOBAR");
    Parameters parameters =
        new Parameters("foobar", "foobiz", "foobuz", "fizbiz", "fuz", "fiz", 1, "foo", "bar");
    Normalized normalized = new Normalized("foo", "bar", "fiz", "biz", "fixbiz");
    Source source = new Source("FUZBUZ", "FIZBIZ");
    Transaction transaction =
        new Transaction(
            "foobar",
            "foobiz",
            denomination,
            destination,
            fees,
            "fuzbuz",
            "qux",
            normalizeds,
            origin,
            parameters,
            "fizbiz",
            "foobuz",
            "foo");

    fees.add(fee);
    normalizeds.add(normalized);
    sources.add(source);

    byte[] serializedTransaction = SerializationUtils.serialize(transaction);
    Transaction deserializedTransaction = SerializationUtils.deserialize(serializedTransaction);

    Assert.assertEquals(transaction.getCreatedAt(), deserializedTransaction.getCreatedAt());
    Assert.assertEquals(
        transaction.getDenomination().getAmount(),
        deserializedTransaction.getDenomination().getAmount());
    Assert.assertEquals(
        transaction.getDenomination().getCurrency(),
        deserializedTransaction.getDenomination().getCurrency());
    Assert.assertEquals(
        transaction.getDenomination().getPair(),
        deserializedTransaction.getDenomination().getPair());
    Assert.assertEquals(
        transaction.getDenomination().getRate(),
        deserializedTransaction.getDenomination().getRate());
    Assert.assertEquals(
        transaction.getDestination().getAccountId(),
        deserializedTransaction.getDestination().getAccountId());
    Assert.assertEquals(
        transaction.getDestination().getAccountType(),
        deserializedTransaction.getDestination().getAccountType());
    Assert.assertEquals(
        transaction.getDestination().getAmount(),
        deserializedTransaction.getDestination().getAmount());
    Assert.assertEquals(
        transaction.getDestination().getBase(), deserializedTransaction.getDestination().getBase());
    Assert.assertEquals(
        transaction.getDestination().getCardId(),
        deserializedTransaction.getDestination().getCardId());
    Assert.assertEquals(
        transaction.getDestination().getCommission(),
        deserializedTransaction.getDestination().getCommission());
    Assert.assertEquals(
        transaction.getDestination().getCurrency(),
        deserializedTransaction.getDestination().getCurrency());
    Assert.assertEquals(
        transaction.getDestination().getDescription(),
        deserializedTransaction.getDestination().getDescription());
    Assert.assertEquals(
        transaction.getDestination().getFee(), deserializedTransaction.getDestination().getFee());
    Assert.assertEquals(
        transaction.getDestination().getRate(), deserializedTransaction.getDestination().getRate());
    Assert.assertEquals(
        transaction.getDestination().getType(), deserializedTransaction.getDestination().getType());
    Assert.assertEquals(
        transaction.getDestination().getUsername(),
        deserializedTransaction.getDestination().getUsername());
    Assert.assertEquals(
        transaction.getFees().get(0).getAmount(),
        deserializedTransaction.getFees().get(0).getAmount());
    Assert.assertEquals(
        transaction.getFees().get(0).getCurrency(),
        deserializedTransaction.getFees().get(0).getCurrency());
    Assert.assertEquals(
        transaction.getFees().get(0).getPercentage(),
        deserializedTransaction.getFees().get(0).getPercentage());
    Assert.assertEquals(
        transaction.getFees().get(0).getTarget(),
        deserializedTransaction.getFees().get(0).getTarget());
    Assert.assertEquals(
        transaction.getFees().get(0).getType(), deserializedTransaction.getFees().get(0).getType());
    Assert.assertEquals(transaction.getId(), deserializedTransaction.getId());
    Assert.assertEquals(transaction.getMessage(), deserializedTransaction.getMessage());
    Assert.assertEquals(transaction.getNetwork(), deserializedTransaction.getNetwork());
    Assert.assertEquals(transaction.getNormalized().size(), 1);
    Assert.assertEquals(
        transaction.getNormalized().get(0).getAmount(),
        deserializedTransaction.getNormalized().get(0).getAmount());
    Assert.assertEquals(
        transaction.getNormalized().get(0).getCommission(),
        deserializedTransaction.getNormalized().get(0).getCommission());
    Assert.assertEquals(
        transaction.getNormalized().get(0).getCurrency(),
        deserializedTransaction.getNormalized().get(0).getCurrency());
    Assert.assertEquals(
        transaction.getNormalized().get(0).getFee(),
        deserializedTransaction.getNormalized().get(0).getFee());
    Assert.assertEquals(
        transaction.getNormalized().get(0).getRate(),
        deserializedTransaction.getNormalized().get(0).getRate());
    Assert.assertEquals(
        transaction.getOrigin().getAccountId(), deserializedTransaction.getOrigin().getAccountId());
    Assert.assertEquals(
        transaction.getOrigin().getAccountType(),
        deserializedTransaction.getOrigin().getAccountType());
    Assert.assertEquals(
        transaction.getOrigin().getAmount(), deserializedTransaction.getOrigin().getAmount());
    Assert.assertEquals(
        transaction.getOrigin().getBase(), deserializedTransaction.getOrigin().getBase());
    Assert.assertEquals(
        transaction.getOrigin().getCardId(), deserializedTransaction.getOrigin().getCardId());
    Assert.assertEquals(
        transaction.getOrigin().getCommission(),
        deserializedTransaction.getOrigin().getCommission());
    Assert.assertEquals(
        transaction.getOrigin().getCurrency(), deserializedTransaction.getOrigin().getCurrency());
    Assert.assertEquals(
        transaction.getOrigin().getDescription(),
        deserializedTransaction.getOrigin().getDescription());
    Assert.assertEquals(
        transaction.getOrigin().getFee(), deserializedTransaction.getOrigin().getFee());
    Assert.assertEquals(
        transaction.getOrigin().getRate(), deserializedTransaction.getOrigin().getRate());
    Assert.assertEquals(
        transaction.getOrigin().getSources().size(),
        deserializedTransaction.getOrigin().getSources().size());
    Assert.assertEquals(
        transaction.getOrigin().getSources().get(0).getAmount(),
        deserializedTransaction.getOrigin().getSources().get(0).getAmount());
    Assert.assertEquals(
        transaction.getOrigin().getSources().get(0).getId(),
        deserializedTransaction.getOrigin().getSources().get(0).getId());
    Assert.assertEquals(
        transaction.getOrigin().getType(), deserializedTransaction.getOrigin().getType());
    Assert.assertEquals(
        transaction.getOrigin().getUsername(), deserializedTransaction.getOrigin().getUsername());
    Assert.assertEquals(
        transaction.getParams().getCurrency(), deserializedTransaction.getParams().getCurrency());
    Assert.assertEquals(
        transaction.getParams().getMargin(), deserializedTransaction.getParams().getMargin());
    Assert.assertEquals(
        transaction.getParams().getPair(), deserializedTransaction.getParams().getPair());
    Assert.assertEquals(
        transaction.getParams().getProgress(), deserializedTransaction.getParams().getProgress());
    Assert.assertEquals(
        transaction.getParams().getRate(), deserializedTransaction.getParams().getRate());
    Assert.assertEquals(
        transaction.getParams().getRefunds(), deserializedTransaction.getParams().getRefunds());
    Assert.assertEquals(
        transaction.getParams().getTtl(), deserializedTransaction.getParams().getTtl());
    Assert.assertEquals(
        transaction.getParams().getTxid(), deserializedTransaction.getParams().getTxid());
    Assert.assertEquals(
        transaction.getParams().getType(), deserializedTransaction.getParams().getType());
    Assert.assertEquals(transaction.getRefundedById(), deserializedTransaction.getRefundedById());
    Assert.assertEquals(transaction.getStatus(), deserializedTransaction.getStatus());
    Assert.assertEquals(transaction.getType(), deserializedTransaction.getType());
  }
示例#9
0
 /**
  * 发送消息
  *
  * @param object
  * @throws IOException
  */
 public void sendMessage(Serializable object) throws IOException {
   channel.basicPublish("", endPointName, null, SerializationUtils.serialize(object));
 }
示例#10
0
 /** @return The byte array representation of this object */
 public byte[] getBytes() {
   return SerializationUtils.serialize(this);
 }