001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.io.crypto; 019 020import org.apache.hadoop.conf.Configuration; 021import org.apache.hadoop.hbase.HBaseConfiguration; 022import org.apache.hadoop.hbase.io.crypto.aes.AES; 023import org.apache.yetus.audience.InterfaceAudience; 024 025/** 026 * The default cipher provider. Supports AES via the JCE. 027 */ 028@InterfaceAudience.Public 029public final class DefaultCipherProvider implements CipherProvider { 030 031 private static DefaultCipherProvider instance; 032 033 public static DefaultCipherProvider getInstance() { 034 if (instance != null) { 035 return instance; 036 } 037 instance = new DefaultCipherProvider(); 038 return instance; 039 } 040 041 private Configuration conf = HBaseConfiguration.create(); 042 043 // Prevent instantiation 044 private DefaultCipherProvider() { 045 } 046 047 @Override 048 public Configuration getConf() { 049 return conf; 050 } 051 052 @Override 053 public void setConf(Configuration conf) { 054 this.conf = conf; 055 } 056 057 @Override 058 public String getName() { 059 return "default"; 060 } 061 062 @Override 063 public Cipher getCipher(String name) { 064 if (name.equalsIgnoreCase("AES")) { 065 return new AES(this); 066 } 067 throw new RuntimeException( 068 "Cipher '" + name + "' is not supported by provider '" + getName() + "'"); 069 } 070 071 @Override 072 public String[] getSupportedCiphers() { 073 return new String[] { "AES" }; 074 } 075 076}