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 org.apache.hadoop.conf.Configuration;
020import org.apache.hadoop.hbase.HBaseConfiguration;
021import org.apache.hadoop.hbase.io.crypto.aes.AES;
022import org.apache.yetus.audience.InterfaceAudience;
023
024/**
025 * The default cipher provider. Supports AES via the JCE.
026 */
027@InterfaceAudience.Public
028public final class DefaultCipherProvider implements CipherProvider {
029
030  private static DefaultCipherProvider instance;
031
032  public static DefaultCipherProvider getInstance() {
033    if (instance != null) {
034      return instance;
035    }
036    instance = new DefaultCipherProvider();
037    return instance;
038  }
039
040  private Configuration conf = HBaseConfiguration.create();
041
042  // Prevent instantiation
043  private DefaultCipherProvider() { }
044
045  @Override
046  public Configuration getConf() {
047    return conf;
048  }
049
050  @Override
051  public void setConf(Configuration conf) {
052    this.conf = conf;
053  }
054
055  @Override
056  public String getName() {
057    return "default";
058  }
059
060  @Override
061  public Cipher getCipher(String name) {
062    if (name.equalsIgnoreCase("AES")) {
063      return new AES(this);
064    }
065    throw new RuntimeException("Cipher '" + name + "' is not supported by provider '" +
066        getName() + "'");
067  }
068
069  @Override
070  public String[] getSupportedCiphers() {
071    return new String[] { "AES" };
072  }
073
074}