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