io.lettuce.core.RedisException: java.lang.RuntimeException: неверный ключ или спецификация в режиме GCM - PullRequest
0 голосов
/ 24 мая 2019

Я использую библиотеку Lettuce (5.1.6.Release) в качестве клиента Java Redis для создания соединения с Redis.

Ниже приведен фрагмент кода из моего приложения SpringBoot с использованием Java 8.

ClientOptions options =
      ClientOptions.builder()
      .disconnectedBehavior(ClientOptions.DisconnectedBehavior.REJECT_COMMANDS)
                .autoReconnect(true)
                .build();

LettucePoolingClientConfiguration pool = LettucePoolingClientConfiguration.builder()
                .poolConfig(new GenericObjectPoolConfig())
                .clientOptions(options)
                .clientResources(DefaultClientResources.create())
                .useSsl()
                .build();

RedisConnectionFactory factory = new LettuceConnectionFactory(new RedisStandaloneConfiguration("host name string here"), pool);

RedisTemplate<String, String> redisConn = new RedisTemplate<>();
        redisConn.setConnectionFactory(factory);
        redisConn.setKeySerializer(StringRedisSerializer.UTF_8);
        redisConn.setValueSerializer(StringRedisSerializer.UTF_8);
        redisConn.setEnableTransactionSupport(true);

redisConn - это Singlton Spring Bean, используемый во всех службах для добавления данных в Redis

SetOperations<String, String> setOperations = redisTemplate.opsForSet();
setOperations.add("key1", "value1");
setOperations.add("key2", "value2");
setOperations.add("key3", "value3");

Я получаю сообщение об ошибке при выполнении операции добавления в Redis в Java.

org.springframework.data.redis.RedisSystemException: Redis exception; nested exception is io.lettuce.core.RedisException: java.lang.RuntimeException: invalid key or spec in GCM mode
        at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:74) ~[spring-data-redis-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:41) ~[spring-data-redis-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]

     ....

    Caused by: io.lettuce.core.RedisException: java.lang.RuntimeException: invalid key or spec in GCM mode
    at io.lettuce.core.LettuceFutures.awaitOrCancel(LettuceFutures.java:129) ~[lettuce-core-5.1.6.RELEASE.jar!/:?]
    at io.lettuce.core.FutureSyncInvocationHandler.handleInvocation(FutureSyncInvocationHandler.java:69) ~[lettuce-core-5.1.6.RELEASE.jar!/:?]

     ....

    Caused by: java.lang.RuntimeException: invalid key or spec in GCM mode
    at sun.security.ssl.CipherBox.createExplicitNonce(CipherBox.java:1043) ~[?:1.8.0_191]
    at sun.security.ssl.OutputRecord.encrypt(OutputRecord.java:248) ~[?:1.8.0_191]
    at sun.security.ssl.EngineOutputRecord.write(EngineOutputRecord.java:153) ~[?:1.8.0_191]

      ....

    Caused by: java.security.InvalidAlgorithmParameterException: Cannot reuse iv for GCM encryption
    at com.sun.crypto.provider.CipherCore.init(CipherCore.java:583) ~[sunjce_provider.jar:1.8.0_191]
    at com.sun.crypto.provider.AESCipher.engineInit(AESCipher.java:346) ~[sunjce_provider.jar:1.8.0_191]
    at javax.crypto.Cipher.init(Cipher.java:1393) ~[?:1.8.0_191]
...