I want to decrypt and encrypt a string using chacha20
BouncyCastleProvider uses the chacha20 technique. So I turned it into a jar. and tried the code, but could not work.
PBE.java
public class PBE extends AppCompatActivity { private static final String salt = "A long, but constant phrase that will be used each time as the salt."; private static final int iterations = 2000; private static final int keyLength = 256; private static final SecureRandom random = new SecureRandom(); @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.pbe); try { Security.insertProviderAt(new BouncyCastleProvider(), 1);
But that does not give me the correct result.

Change and update code
public class ChaCha20Encryptor implements Encryptor { private final byte randomIvBytes[] = {0, 1, 2, 3, 4, 5, 6, 7}; static { Security.addProvider(new BouncyCastleProvider()); } @Override public byte[] encrypt(byte[] data, byte[] randomKeyBytes) throws IOException, InvalidKeyException, InvalidAlgorithmParameterException, InvalidCipherTextException { ChaChaEngine cipher = new ChaChaEngine(); CipherParameters cp = new KeyParameter(getMyKey(randomKeyBytes)); cipher.init(true, new ParametersWithIV(cp , randomIvBytes));
Now I only have to decrypt the problem. It shows an error that the key must be 128 or 256 bits. What am I doing wrong.
android encryption bouncycastle
Xar E Ahmer Jun 24 '16 at 7:04 2016-06-24 07:04
source share