使用海绵城堡

时间:2016-06-28 12:30:56

标签: java android string encryption byte

  

我只想使用Android在<{1}}中加密和解密文字。

我找到了一些示例,但找不到ChaCha20以正确的方式制作它。我想要solution ChaCha。 someOne可以指导我如何实现它。我试着修改这些代码了很多。

SecurityUtil

encryption

我尝试将public class SecurityUtil extends Properties { public String decrypt(String name, String keyString) throws Exception { BlowfishEngine engine = new BlowfishEngine(); PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(engine); StringBuffer result = new StringBuffer(); KeyParameter key = new KeyParameter(keyString.getBytes()); cipher.init(false, key); byte out[] = Base64.decode(name); byte out2[] = new byte[cipher.getOutputSize(out.length)]; int len2 = cipher.processBytes(out, 0, out.length, out2, 0); cipher.doFinal(out2, len2); String s2 = new String(out2); for (int i = 0; i < s2.length(); i++) { char c = s2.charAt(i); if (c != 0) { result.append(c); } } return result.toString(); } public String encrypt(String value, String keyString) throws Exception { BlowfishEngine engine = new BlowfishEngine(); PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(engine); KeyParameter key = new KeyParameter(keyString.getBytes()); cipher.init(true, key); byte in[] = value.getBytes(); byte out[] = new byte[cipher.getOutputSize(in.length)]; int len1 = cipher.processBytes(in, 0, in.length, out, 0); try { cipher.doFinal(out, len1); } catch (CryptoException e) { e.printStackTrace(); throw new Exception(e.getMessage()); } String s = new String(Base64.encode(out)); return s; } } 更改为BlowfishEngine,但它是一个类而不是接口。并尝试了很多方法。

AESWrapper

ChaChaEngine

是否有一种简单的方法可以使用chacha简单地加密和解密文本。

0 个答案:

没有答案