summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openecomp/sparky/util/EncryptConvertor.java
diff options
context:
space:
mode:
authorArul.Nambi <arul.nambi@amdocs.com>2017-09-26 14:00:57 -0400
committerArul.Nambi <arul.nambi@amdocs.com>2017-09-26 14:01:41 -0400
commitc593dfe4c59d37d5d4ea14e3ac31da3318029562 (patch)
tree76cc5a494f02e14b809caad9c050fbfd6cd61a51 /src/main/java/org/openecomp/sparky/util/EncryptConvertor.java
parent6777c6092050a0271c5d7de9c239cf1580d41fa8 (diff)
Renaming openecomp to onap
Issue-ID: AAI-208 Change-Id: I2bd02287bed376111156aca0100e2b7b74e368e3 Signed-off-by: Arul.Nambi <arul.nambi@amdocs.com>
Diffstat (limited to 'src/main/java/org/openecomp/sparky/util/EncryptConvertor.java')
-rw-r--r--src/main/java/org/openecomp/sparky/util/EncryptConvertor.java147
1 files changed, 0 insertions, 147 deletions
diff --git a/src/main/java/org/openecomp/sparky/util/EncryptConvertor.java b/src/main/java/org/openecomp/sparky/util/EncryptConvertor.java
deleted file mode 100644
index 2b9dcc9..0000000
--- a/src/main/java/org/openecomp/sparky/util/EncryptConvertor.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 Amdocs
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- */
-package org.openecomp.sparky.util;
-
-/**
- * The Class EncryptConvertor.
- */
-public class EncryptConvertor {
-
- private static final char[] HEX_CHARS = "0123456789abcdef".toCharArray();
-
- /**
- * toHexString(String) - convert a string into its hex equivalent.
- *
- * @param buf the buf
- * @return the string
- */
- public static final String toHexString(String buf) {
- if (buf == null) {
- return "";
- }
- return toHexString(buf.getBytes());
- }
-
- /**
- * toHexString(byte[]) - convert a byte-string into its hex equivalent.
- *
- * @param buf the buf
- * @return the string
- */
- public static final String toHexString(byte[] buf) {
-
- if (buf == null) {
- return "";
- }
- char[] chars = new char[2 * buf.length];
- for (int i = 0; i < buf.length; ++i) {
- chars[2 * i] = HEX_CHARS[(buf[i] & 0xF0) >>> 4];
- chars[2 * i + 1] = HEX_CHARS[buf[i] & 0x0F];
- }
- return new String(chars);
- }
-
- /**
- * Convert a hex string to its equivalent value.
- *
- * @param hexString the hex string
- * @return the string
- * @throws Exception the exception
- */
- public static final String stringFromHex(String hexString) throws Exception {
- if (hexString == null) {
- return "";
- }
- return stringFromHex(hexString.toCharArray());
- }
-
- /**
- * String from hex.
- *
- * @param hexCharArray the hex char array
- * @return the string
- * @throws Exception the exception
- */
- public static final String stringFromHex(char[] hexCharArray) throws Exception {
- if (hexCharArray == null) {
- return "";
- }
- return new String(bytesFromHex(hexCharArray));
- }
-
- /**
- * Bytes from hex.
- *
- * @param hexString the hex string
- * @return the byte[]
- * @throws Exception the exception
- */
- public static final byte[] bytesFromHex(String hexString) throws Exception {
- if (hexString == null) {
- return new byte[0];
- }
- return bytesFromHex(hexString.toCharArray());
- }
-
- /**
- * Bytes from hex.
- *
- * @param hexCharArray the hex char array
- * @return the byte[]
- * @throws Exception the exception
- */
- public static final byte[] bytesFromHex(char[] hexCharArray) throws Exception {
- if (hexCharArray == null) {
- return new byte[0];
- }
- int len = hexCharArray.length;
- if ((len % 2) != 0) {
- throw new Exception("Odd number of characters: '" + String.valueOf(hexCharArray) + "'");
- }
- byte[] txtInByte = new byte[len / 2];
- int counter = 0;
- for (int i = 0; i < len; i += 2) {
- txtInByte[counter++] =
- (byte) (((fromHexDigit(hexCharArray[i], i) << 4) | fromHexDigit(hexCharArray[i + 1], i))
- & 0xFF);
- }
- return txtInByte;
- }
-
- /**
- * From hex digit.
- *
- * @param ch the ch
- * @param index the index
- * @return the int
- * @throws Exception the exception
- */
- protected static final int fromHexDigit(char ch, int index) throws Exception {
- int digit = Character.digit(ch, 16);
- if (digit == -1) {
- throw new Exception("Illegal hex character '" + ch + "' at index " + index);
- }
- return digit;
- }
-
-}