Code Monkey home page Code Monkey logo

Comments (10)

iamironz avatar iamironz commented on May 25, 2024

Hi.
Thanks for issue submitting.
I will investigate this as soon as possible.

Regards.

from binaryprefs.

iamironz avatar iamironz commented on May 25, 2024

@balamyt I see that you has no have default constructor for MyEntity class. You actually don't?

from binaryprefs.

iamironz avatar iamironz commented on May 25, 2024

Also your customEncryptor#encrypt or recrypt field's methods implementation returns correct encrypted result or byte[0] ?

from binaryprefs.

iamironz avatar iamironz commented on May 25, 2024

This usually happens if you provide empty byte array into FileAdapter for saving.

from binaryprefs.

iamironz avatar iamironz commented on May 25, 2024

Also try to use no-op encryption to replay the situation: https://github.com/iamironz/binaryprefs/blob/master/library/src/main/java/com/ironz/binaryprefs/encryption/ByteEncryption.java#L27-L37

from binaryprefs.

balamyt avatar balamyt commented on May 25, 2024

I see that you has no have default constructor for MyEntity class. You actually don't?
Yes, I have not default constructor.

my customEncryptor#encrypt:

   @Override
   public byte[] encrypt(byte[] bytes) {
      if (!hasAlias()) {
         throw createExceptionForDevelopment("set aliases to keystore before encrypt");
      }

      try {
         KeyStore.PrivateKeyEntry privateKeyEntry = (KeyStore.PrivateKeyEntry) mKeyStore.getEntry(mAlias, null);
         RSAPublicKey publicKey = (RSAPublicKey) privateKeyEntry.getCertificate().getPublicKey();

         Cipher inCipher = Cipher.getInstance("RSA/ECB/PKCS1Padding", "AndroidOpenSSL");
         inCipher.init(Cipher.ENCRYPT_MODE, publicKey);

         return encrypt(bytes, inCipher);

      } catch (NoSuchAlgorithmException | UnrecoverableEntryException | KeyStoreException | NoSuchProviderException e) {
         throw createExceptionForUser("in encrypt() something wrong at process with encryption", e, e.getLocalizedMessage());
      } catch (NoSuchPaddingException | InvalidKeyException e) {
         throw createExceptionForDevelopment("need check to correct alias before");
      }
   }

   private byte[] encrypt(byte[] bytes, Cipher inCipher) throws AppKeystoreException {
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      CipherOutputStream cipherOutputStream = new CipherOutputStream(outputStream, inCipher);
      try {
         cipherOutputStream.write(bytes);
         return outputStream.toByteArray();
      } catch (IOException e) {
         throw createExceptionForUser("in encrypt() something wrong at process with cipherOutputStream", e, e.getLocalizedMessage());
      } finally {
         CloseableUtils.close(cipherOutputStream);
      }
   }

from binaryprefs.

iamironz avatar iamironz commented on May 25, 2024

@balamyt try create an unit test which encrypts and decrypts non-empty byte[] value with your encryption.

from binaryprefs.

iamironz avatar iamironz commented on May 25, 2024

Also please note that you should have default constructor because during initialization it will be called.

from binaryprefs.

balamyt avatar balamyt commented on May 25, 2024

Thank!!
It's all right!
The problem was my encryption implementation.

from binaryprefs.

iamironz avatar iamironz commented on May 25, 2024

Also i've added two stages byte array length checking:

iamironz@bf0ef9d
iamironz@53678f7

This checks will be in 1.0.0-ALPHA1 release.

Regards.

from binaryprefs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.