MCPcopy Create free account
hub / github.com/M66B/FairEmail / transform

Method transform

app/src/main/java/eu/faircode/email/CloudSync.java:795–813  ·  view source on GitHub ↗
(String value, byte[] key, byte[] iv, byte[] ad, boolean encrypt)

Source from the content-addressed store, hash-verified

793 }
794
795 private static String transform(String value, byte[] key, byte[] iv, byte[] ad, boolean encrypt)
796 throws InvalidCipherTextException, IOException {
797 GCMSIVBlockCipher cipher = new GCMSIVBlockCipher(new AESEngine());
798 AEADParameters aead = new AEADParameters(new KeyParameter(key), 128, iv, ad);
799 cipher.init(encrypt, aead);
800
801 byte[] input = (encrypt
802 ? compress(value.getBytes())
803 : Base64.decode(value, Base64.NO_PADDING | Base64.NO_WRAP));
804 int outputLength = cipher.getOutputSize(input.length);
805 byte[] output = new byte[outputLength];
806 int outputOffset = cipher.processBytes(input, 0, input.length, output, 0);
807 outputOffset += cipher.doFinal(output, outputOffset); // tag
808 if (outputOffset != outputLength)
809 throw new IllegalStateException("offset=" + outputOffset + "/" + outputLength);
810 return (encrypt
811 ? Base64.encodeToString(output, Base64.NO_PADDING | Base64.NO_WRAP)
812 : new String(decompress(output)));
813 }
814
815 public static byte[] compress(byte[] data) throws IOException {
816 try (ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length)) {

Callers 2

_callMethod · 0.95
getMSAutodiscoveryMethod · 0.80

Calls 5

compressMethod · 0.95
decompressMethod · 0.95
initMethod · 0.45
getBytesMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected