Am facing the following error while trying to decrpyt a cipher string using Google KSM SDK version 1.40.0
.
Code used:
try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) {
CryptoKeyName name = CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]");
ByteString ciphertext = ByteString.copyFromUtf8("");
DecryptResponse response = keyManagementServiceClient.decrypt(name.toString(), ciphertext);
}
Error:
Caused by: java.lang.IllegalAccessError: tried to access field com.google.protobuf.AbstractMessage.memoizedSize from class com.google.cloud.kms.v1.DecryptRequest
at com.google.cloud.kms.v1.DecryptRequest.getSerializedSize(DecryptRequest.java:472)
at io.grpc.protobuf.lite.ProtoInputStream.available(ProtoInputStream.java:108)
at io.grpc.internal.MessageFramer.getKnownLength(MessageFramer.java:205)
at io.grpc.internal.MessageFramer.writePayload(MessageFramer.java:137)
at io.grpc.internal.AbstractStream.writeMessage(AbstractStream.java:65)
at io.grpc.internal.ForwardingClientStream.writeMessage(ForwardingClientStream.java:37)
at io.grpc.internal.ClientCallImpl.sendMessageInternal(ClientCallImpl.java:544)
at io.grpc.internal.ClientCallImpl.sendMessage(ClientCallImpl.java:528)
at io.grpc.ForwardingClientCall.sendMessage(ForwardingClientCall.java:37)
at io.grpc.stub.ClientCalls.asyncUnaryRequestCall(ClientCalls.java:308)
at io.grpc.stub.ClientCalls.futureUnaryCall(ClientCalls.java:218)
at com.google.api.gax.grpc.GrpcDirectCallable.futureCall(GrpcDirectCallable.java:58)
at com.google.api.gax.grpc.GrpcUnaryRequestParamCallable.futureCall(GrpcUnaryRequestParamCallable.java:65)
at com.google.api.gax.grpc.GrpcExceptionCallable.futureCall(GrpcExceptionCallable.java:64)
at com.google.api.gax.rpc.AttemptCallable.call(AttemptCallable.java:86)
at com.google.api.gax.rpc.RetryingCallable.futureCall(RetryingCallable.java:63)
at com.google.api.gax.rpc.RetryingCallable.futureCall(RetryingCallable.java:41)
at com.google.api.gax.tracing.TracedUnaryCallable.futureCall(TracedUnaryCallable.java:75)
at com.google.api.gax.rpc.UnaryCallable$1.futureCall(UnaryCallable.java:126)
at com.google.api.gax.rpc.UnaryCallable.futureCall(UnaryCallable.java:87)
... 27 more
Please help.
This is because you have different versions of protobuf in the classpath. Use some shade plugins to rename the proto class in the final build jar.
Example sbt (assembly) ::: https://github.com/sbt/sbt-assembly#shading