Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.security.Key;

import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;

public class Main {
    public static Key updGenerateKey(String key) {
        try {
            DESedeKeySpec KeySpec = new DESedeKeySpec(UdpHexDecode(key));
            SecretKeyFactory KeyFactory = SecretKeyFactory.getInstance("DESede");
            Key k = ((KeyFactory.generateSecret(((KeySpec)))));
            return k;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static byte[] UdpHexDecode(String s) {
        byte abyte0[] = new byte[s.length() / 2];
        String s1 = s.toLowerCase();
        for (int i = 0; i < s1.length(); i += 2) {
            char c = s1.charAt(i);
            char c1 = s1.charAt(i + 1);
            int j = i / 2;
            if (c < 'a')
                abyte0[j] = (byte) (c - 48 << 4);
            else
                abyte0[j] = (byte) ((c - 97) + 10 << 4);
            if (c1 < 'a')
                abyte0[j] += (byte) (c1 - 48);
            else
                abyte0[j] += (byte) ((c1 - 97) + 10);
        }
        return abyte0;
    }
}