I am trying to use tink to encrypt data.
My initialization routine is as follows:
try {
AeadConfig.register();
} catch (GeneralSecurityException e) {
e.printStackTrace();
}
This is throwing an exception:
tried to access field com.google.protobuf.AbstractMessage.memoizedSize from class com.google.crypto.tink.proto.HmacKeyFormat
java.lang.IllegalAccessError: tried to access field com.google.protobuf.AbstractMessage.memoizedSize from class com.google.crypto.tink.proto.HmacKeyFormat
at com.google.crypto.tink.proto.HmacKeyFormat.getSerializedSize(HmacKeyFormat.java:182)
at com.google.protobuf.AbstractMessageLite.toByteArray(AbstractMessageLite.java:62)
at com.google.crypto.tink.Registry.registerKeyTemplates(Registry.java:653)
at com.google.crypto.tink.Registry.registerKeyManager(Registry.java:556)
at com.google.crypto.tink.mac.HmacKeyManager.register(HmacKeyManager.java:232)
at com.google.crypto.tink.mac.MacConfig.register(MacConfig.java:86)
at com.google.crypto.tink.mac.MacConfig.init(MacConfig.java:74)
at com.google.crypto.tink.mac.MacConfig.<clinit>(MacConfig.java:59)
at com.google.crypto.tink.aead.AeadConfig.register(AeadConfig.java:102)
at com.google.crypto.tink.aead.AeadConfig.init(AeadConfig.java:86)
at com.google.crypto.tink.aead.AeadConfig.<clinit>(AeadConfig.java:68)
at com.zillow.kafka.message.MessageEncryptor.<init>(MessageEncryptor.java:24)
at com.zillow.kafka.message.MessageEncryptorTest.testSimple(MessageEncryptorTest.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:138)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
here is my gradle
buildscript {
repositories {
jcenter()
mavenCentral()
maven {
url = "https://packages.confluent.io/maven"
}
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
}
}
plugins {
id 'java' // so that we can use 'implementation', 'testImplementation' for dependencies
}
apply plugin: 'com.github.johnrengelman.shadow'
repositories {
jcenter()
mavenCentral()
maven {
url = "https://packages.confluent.io/maven"
}
maven {
url = "https://jitpack.io"
}
}
dependencies {
implementation 'org.apache.avro:avro:1.9.0'
implementation 'org.apache.avro:avro-tools:1.9.0'
// Kafka
implementation "org.apache.kafka:kafka_2.12:2.2.0"
implementation 'org.apache.avro:avro:1.9.0'
implementation 'io.confluent:kafka-schema-registry-client:6.2.1'
implementation 'io.confluent:kafka-avro-serializer:6.2.1'
implementation 'io.confluent:kafka-json-serializer:6.2.1'
implementation 'io.confluent:kafka-json-schema-provider:6.2.1'
implementation 'com.google.crypto.tink:tink:1.6.1'
//test
testImplementation(platform('org.junit:junit-bom:5.9.0'))
testImplementation('org.junit.jupiter:junit-jupiter')
}
sourceSets {
main {
java {
srcDirs = ["src/main/java"]
}
resources {
srcDirs = ["src/main/avro", "src/main/resources"]
}
}
test {
java {
srcDirs = ["src/test/java"]
}
}
}
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}
plugins.withId("com.github.johnrengelman.shadow"){
//this block requires the java plugin to be applied first.
plugins.withId("java"){
shadowJar {
//We are overriding the default jar to be the shadow jar
classifier = null
exclude 'META-INF'
exclude 'META-INF/*.INF'
exclude 'META-INF/license/*'
}
jar {
manifest {
attributes(
'Built-By' : System.properties['user.name'],
'Build-Timestamp': new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()),
'Created-By' : "Gradle ${gradle.gradleVersion}",
'Build-Jdk' : "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})",
'Build-OS' : "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}" ,
)
}
}
tasks.build.dependsOn tasks.shadowJar
tasks.shadowJar.mustRunAfter tasks.jar
}
}
Any idea what I am doing wrong?
[EDIT] I saw in a google search that somebody else hit the same problem, and it was due to a conflicting version of protobuf on the classpath. However, in my case there is no conflicting version. I verified using gradle dependencies
+--- com.google.crypto.tink:tink:1.6.1
| +--- com.google.protobuf:protobuf-java:3.14.0
| \--- com.google.code.gson:gson:2.8.6
nvm.. this was happening because my intellij project import was corrupted.
removing it and reimporting the gradle project fixed the problem.