I have seen all of your internal classes are all about encrypt & decrypt.
you can do it easily by define a top-level function and mark it as @JvmSynthetic
, and then makes the ECryptSymmetricDecrypt and ECryptSymmetricEncrypt classes to private to prevent Java client access your internal classes, for example:
// define this top-level function in your ECryptSymmetricEncrypt.kt
@JvmSynthetic internal fun <T> encrypt(
input:T, password: String, cipher:Cihper,
erl: ECryptResultListener, outputFile:File,
getKey:(String,ByteArray)->SecretKeySpec){
ECryptSymmetricEncrypt(input, password, cipher,
{ pass, salt -> getKey(pass, salt) }, erl, outputFile)
}
However, it solved your problem, but I still want to say that your code can break into small pieces as further. for example, the encrypt & decrypt algorithm have many duplications, maybe you can applies Template Method Pattern in your encrypt library & introduce interfaces to make your library explicitly and hiding the Cipher
operations under the implementation classes. Ideally, the client code can't see any java.security.*
classes via Encrypt
or Decrypt
interfaces. for example:
interface Encrypt{
// v--- don't include the infrastructure class here,e.g:`Keys`,`Cipher`
fun encode(...args)
}
interface Decrypt{
// v--- don't include the infrastructure class here,e.g:`Keys`,`Cipher`
fun decode(...args)
}
AND it is a bad thing that you create an instance and compute the result in init
block here.
AND you can use Factory Method Pattern to avoid the type checking both in ECryptSymmetricDecrypt and ECryptSymmetricEncrypt classes.
@PublishedApi
only support for warnings, but the client code can forcing to call your internal classes. – Trenchantprivate
– Plumeinternal
modules are supposed to be for internal use only which works perfectly in Kotlin app. There is nothing to be exposed there. The problem is with interoperability from Kotlin to Java and not with the design I believe. – Plumeprivate
is the way but the problem is that class is very big and making it innerclass
will further reduce the readability of theclass
. – Plumeas Int
. – Plumeinternal object
with@JvmSynthetic internal fun
which does the thing. Check here github.com/ryan652/EasyCrypt/blob/master/easycrypt/src/main/… – Plume