001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with this
004 * work for additional information regarding copyright ownership. The ASF
005 * licenses this file to you under the Apache License, Version 2.0 (the
006 * "License"); you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014 * License for the specific language governing permissions and limitations under
015 * the License.
016 */
017package org.apache.hadoop.hbase.io.crypto;
018
019import java.security.Key;
020import javax.crypto.spec.SecretKeySpec;
021
022/**
023 * Return a fixed secret key for AES for testing.
024 */
025public class KeyProviderForTesting implements KeyProvider {
026
027  @Override
028  public void init(String parameters) { }
029
030  @Override
031  public Key getKey(String name) {
032    return new SecretKeySpec(Encryption.hash128(name), "AES");
033  }
034
035  @Override
036  public Key[] getKeys(String[] aliases) {
037    Key[] result = new Key[aliases.length];
038    for (int i = 0; i < aliases.length; i++) {
039      result[i] = new SecretKeySpec(Encryption.hash128(aliases[i]), "AES");
040    }
041    return result;
042  }
043}