001/* 002 * Copyright 2018 The shiro-root contributors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.apache.shiro.lang.util; 018 019import java.util.Arrays; 020 021public final class ByteUtils { 022 023 private ByteUtils() { 024 // private utility class 025 } 026 027 /** 028 * For security, sensitive information in array should be zeroed-out at end of use (SHIRO-349). 029 * 030 * @param value An array holding sensitive data 031 */ 032 public static void wipe(Object value) { 033 if (value instanceof byte[]) { 034 byte[] array = (byte[]) value; 035 Arrays.fill(array, (byte) 0); 036 } else if (value instanceof char[]) { 037 char[] array = (char[]) value; 038 Arrays.fill(array, '\u0000'); 039 } 040 } 041 042}