io.lettuce.core.RedisException:java.lang.RuntimeException:GCM模式下的无效密钥或规范

时间:2019-05-24 09:07:58

标签: java spring java-ee spring-data lettuce

我正在使用Lettuce库(5.1.6.Release)作为Java Redis客户端与Redis建立连接。

以下是使用Java 8的SpringBoot应用程序中的代码段。

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");

在执行服务提供的Java单线程中的Redis中执行添加操作时,我遇到以下错误

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]

0 个答案:

没有答案