import java.security.InvalidKeyException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.SecretKeySpec; import sun.misc.BASE64Encoder; import com.kingdee.util.Base64Encoder; public class Jiami { private static final byte[] pwd = { -82, -101, 127, 52, -8, -108, 2, 93 }; public static void main(String[] args) { /** * administrator用户登录,默认密码为空,点修改密码后,写入123, * 在传到后台的时候会用encrypt1加密password,用decrypt对密文解密, * 之后用encrypt2对ID和pw原文组合的字符串进行加密 * administrator的FID=00000000-0000-0000-0000-00000000000013B7DE7F */ Jiami jiami = new Jiami(); String number = "gaofei04"; String pw = "1234abcd"; String houtai = jiami.encrypt1(number, pw); System.out.println("后台="+houtai); String houtaijiemi = jiami.decrypt(number,houtai); System.out.println("后台解密="+houtaijiemi); String fid ="00000000-0000-0000-0000-00000000000013B7DE7F"; String zuizhongjiamimingwen = fid+houtaijiemi; String zuizhongmiwen = jiami.encrypt2(zuizhongjiamimingwen); System.out.println("最终密文="+zuizhongmiwen); } public String encrypt1(String paramString1, String paramString2) { SecretKeySpec localSecretKeySpec = new SecretKeySpec(pwd, "DES"); Cipher localCipher; try { localCipher = Cipher.getInstance("DES"); localCipher.init(1, localSecretKeySpec); byte[] arrayOfByte = localCipher.doFinal(paramString2.getBytes()); String str = Base64Encoder.byteArrayToBase64(arrayOfByte); return str; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } return null; } /**strSrc=用户FID+pw明文 * @date 2012-5-22下午09:31:49 * @author fans * @param strSrc * @return */ public String encrypt2(String strSrc) { String strEncode = null; byte[] btKey = new byte[strSrc.getBytes().length + 1]; System.arraycopy(strSrc.getBytes(), 0, btKey, 0, strSrc.getBytes().length); try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(btKey); byte[] btDigest = md.digest(); BASE64Encoder encoder = new BASE64Encoder(); strEncode = encoder.encode(btDigest); } catch (Exception e) { e.printStackTrace(); } return strEncode; } public String decrypt(String paramString1, String paramString2) { SecretKeySpec localSecretKeySpec = new SecretKeySpec(pwd, "DES"); try { Cipher localCipher = Cipher.getInstance("DES"); localCipher.init(2, localSecretKeySpec); byte[] arrayOfByte = Base64Encoder.base64ToByteArray(paramString2); String str = new String(localCipher.doFinal(arrayOfByte)); return str; } catch (NoSuchAlgorithmException localNoSuchAlgorithmException) { localNoSuchAlgorithmException.printStackTrace(); } catch (NoSuchPaddingException localNoSuchPaddingException) { localNoSuchPaddingException.printStackTrace(); } catch (InvalidKeyException localInvalidKeyException) { localInvalidKeyException.printStackTrace(); } catch (IllegalStateException localIllegalStateException) { localIllegalStateException.printStackTrace(); } catch (IllegalBlockSizeException localIllegalBlockSizeException) { localIllegalBlockSizeException.printStackTrace(); } catch (BadPaddingException localBadPaddingException) { localBadPaddingException.printStackTrace(); } return null; } }
package com.sct.service.impl.recharge; import java.io.ByteArrayOutputStream; /** * Class decodes a Base64 encoded string back into the original byte representation * that can be read as byte array. * * @author <a href="mailto:ralf DOT joachim AT syscon DOT eu">Ralf Joachim</a> * @version $Revision: 6907 $ $Date: 2005-08-05 13:58:36 -0600 (Fri, 05 Aug 2005) $ * @since 0.9.9 */ public final class Base64Decoder { /** Mask buffer to or with first sextet. */ private static final int SEXTET_1_MASK = 0x03FFFF; /** Mask buffer to or with second sextet. */ private static final int SEXTET_2_MASK = 0xFC0FFF; /** Mask buffer to or with third sextet. */ private static final int SEXTET_3_MASK = 0xFFF03F; /** Mask buffer to or with forth sextet. */ private static final int SEXTET_4_MASK = 0xFFFFC0; /** Number of bits to shift for one sextet. */ private static final int SHIFT_1_SEXTET = 6; /** Number of bits to shift for two sextet. */ private static final int SHIFT_2_SEXTET = 12; /** Number of bits to shift for three sextet. */ private static final int SHIFT_3_SEXTET = 18; /** Second sextets in buffer. */ private static final int SEXTET_2 = 2; /** Third sextets in buffer. */ private static final int SEXTET_3 = 3; /** Forth sextets in buffer. */ private static final int SEXTET_4 = 4; /** Mask an octet. */ private static final int OCTET_MASK = 0xFF; /** Number of bits to shift for one octet. */ private static final int SHIFT_1_OCTET = 8; /** Number of bits to shift for two octet. */ private static final int SHIFT_2_OCTET = 16; /** White space character (out of range 0 - 63). */ private static final byte SPC = 127; /** Padding character (out of range 0 - 63). */ private static final byte PAD = 64; /** Array to translate base64 characters into sextet byte values. */ private static final byte[] MAP = { SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, // 00-07 SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, // 08-0F SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, // 10-17 SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, // 18-1F SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, // 20-27 SPC, SPC, SPC, 62, SPC, SPC, SPC, 63, // 28-2F ' + /' 52, 53, 54, 55, 56, 57, 58, 59, // 30-37 '01234567' 60, 61, SPC, SPC, SPC, PAD, SPC, SPC, // 38-3F '89 = ' SPC, 0, 1, 2, 3, 4, 5, 6, // 40-47 ' ABCDEFG' 7, 8, 9, 10, 11, 12, 13, 14, // 48-4F 'HIJKLMNO' 15, 16, 17, 18, 19, 20, 21, 22, // 50-57 'PQRSTUVW' 23, 24, 25, SPC, SPC, SPC, SPC, SPC, // 58-5F 'XYZ ' SPC, 26, 27, 28, 29, 30, 31, 32, // 60-67 ' abcdefg' 33, 34, 35, 36, 37, 38, 39, 40, // 68-6F 'hijklmno' 41, 42, 43, 44, 45, 46, 47, 48, // 70-77 'pqrstuvw' 49, 50, 51, SPC, SPC, SPC, SPC, SPC, // 78-7F 'xyz ' SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, // 80-87 SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, // 88-8F SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, // 90-97 SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, // 98-9F SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, // A0-A7 SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, // A8-AF SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, // B0-B7 SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, // B8-BF SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, // C0-C7 SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, // C8-CF SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, // D0-D7 SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, // D8-DF SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, // E0-E7 SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, // E8-EF SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, // F0-F7 SPC, SPC, SPC, SPC, SPC, SPC, SPC, SPC, // F8-FF }; /** 24-bit buffer to translate 4 sextets into 3 octets. */ private int _buffer = 0; /** Number of octets in buffer. */ private int _sextets = 0; /** Stream buffer for decoded octets waiting to be read. */ private ByteArrayOutputStream _stream = new ByteArrayOutputStream(); /** * Decode given string into a decoded byte array. * * @param str Base64 String to be decoded. * @return All decoded octets as byte array. */ public static byte[] decode(final String str) { Base64Decoder dec = new Base64Decoder(); dec.translate(str); return dec.getByteArray(); } /** * Construct a default Base64Decoder waiting on calls to its translate() * method. */ public Base64Decoder() { } /** * Translate every base64 character from given string into a sextet byte value * by using above translation array. The sextets are then shiftet into an buffer * until the buffer contains 4 sextets which are then decoded into 3 octets. * The translate and decode process is continued until all characters of given * string are evaluated. If there are remaing sextets in the buffer they also * will be converted into octets at the end. All the converted octets are added * to the list for later read. * * @param string Base64 String to be decoded. */ public void translate(final String string) { int len = string.length(); int index = 0; int data = MAP[string.charAt(index)]; while ((index < len) && (data != PAD)) { if (data != SPC) { if (_sextets == 0) { _buffer = (_buffer & SEXTET_1_MASK) | (data << SHIFT_3_SEXTET); } else if (_sextets == 1) { _buffer = (_buffer & SEXTET_2_MASK) | (data << SHIFT_2_SEXTET); } else if (_sextets == 2) { _buffer = (_buffer & SEXTET_3_MASK) | (data << SHIFT_1_SEXTET); } else { _buffer = (_buffer & SEXTET_4_MASK) | data; } if ((++_sextets) == SEXTET_4) { decode(); } } if (++index < len) { data = MAP[string.charAt(index)]; } } if (_sextets > 0) { decodeWithPadding(); } } /** * Decode 3 octets from buffer and add them to list of octets to read. */ private void decode() { _stream.write((byte) ((_buffer >> SHIFT_2_OCTET) & OCTET_MASK)); // octet 1 _stream.write((byte) ((_buffer >> SHIFT_1_OCTET) & OCTET_MASK)); // octet 2 _stream.write((byte) (_buffer & OCTET_MASK)); // octet 3 _buffer = 0; _sextets = 0; } /** * Decode the remaining octets from buffer and add them to list of octets to read. */ private void decodeWithPadding() { if (_sextets >= SEXTET_2) { // octet 1 _stream.write((byte) ((_buffer >> SHIFT_2_OCTET) & OCTET_MASK)); } if (_sextets >= SEXTET_3) { // octet 2 _stream.write((byte) ((_buffer >> SHIFT_1_OCTET) & OCTET_MASK)); } if (_sextets >= SEXTET_4) { // octet 3 _stream.write((byte) (_buffer & OCTET_MASK)); } _buffer = 0; _sextets = 0; } /** * Get all decoded octets as byte array. * * @return All decoded octets as byte array. */ public byte[] getByteArray() { return _stream.toByteArray(); } }
相关推荐
在早期版本如AIX5.3 TL07之前,AIX主要使用的是传统的`crypt`加密方法,这种加密方式基于DES算法,并且提供salt机制。但在AIX5.3 TL07之后,为了增强安全性,AIX引入了更为安全的加密方法,例如MD5、SHA-1和SHA-256...
本文将详细探讨几种简单但常用的加密方式,以及如何实现这些加密方法。 首先,我们来看MD5(Message-Digest Algorithm 5)哈希加密。MD5是一种广泛使用的哈希函数,它能够将任意长度的输入(也叫做预映射pre-image...
本文将详细介绍如何搭建一个采用WEP加密方式的无线网络,以及在这个过程中可能涉及到的相关知识点。 首先,我们需要了解WEP的基本原理。WEP是为无线局域网(WLAN)设计的一种安全协议,它的目标是提供与有线网络...
针对 SQL Server 2008 存储过程通过 With Encryption 加密方式的解密 SQL Server 2008 存储过程中使用 With Encryption 加密方式可以对存储过程进行加密保护,以防止未经授权的访问和修改。但是,在某些情况下,...
java三种加密方式java三种加密方式java三种加密方式java三种加密方式java三种加密方式java三种加密方式java三种加密方式java三种加密方式java三种加密方式java三种加密方式java三种加密方式java三种加密方式java三种...
在这个"ASP.NET各种加密方式DEMO"中,我们将会探讨多种加密技术,这些技术在保护用户数据安全、防止信息泄露以及验证数据完整性方面发挥着关键作用。 首先,让我们来看看MD5(Message-Digest Algorithm 5)。MD5是...
无线网络管查看工具是为了解决这一问题而设计的专业软件,它能帮助用户轻松地检查和管理自己的无线网络环境,特别是对于无线信号的加密方式进行查看。本文将深入探讨无线网络、管理工具、无线信号以及加密方式等关键...
DES加/解密解密算法、MD5、RC2等等多种加密方式供各用户参考,都是C#版的。欢迎下载
本文将深入探讨C#中的几种主要加密方式,包括对称加密、非对称加密、哈希函数和数字签名等,以及它们在实际应用中的使用场景。 1. 对称加密:对称加密是最常见的加密方法,因为它的速度非常快,适用于大量数据的...
安全加密方式是保护数据免受未经授权访问或篡改的关键技术,尤其在当今数字化时代,信息安全的重要性日益凸显。本文将深入探讨“security加密方式”,包括其基本原理、常见类型以及实际应用。 加密是一种将明文(可...
邮件的加密方式 在现代通信时代,电子邮件已经成为日常生活和商业活动中不可或缺的一部分。然而,电子邮件在传输过程中很容易遭到非法截获和篡改,导致敏感信息泄露。这就需要我们对电子邮件进行加密,以保护其安全...
在IT行业中,加密技术是确保数据安全的重要手段。Delphi是一种流行的面向对象的编程环境,它广泛用于开发桌面应用程序。本篇文章将详细讲解Delphi中涉及的加密技术,包括MD5散列和DES加密,以及可能存在的自定义加密...
Java 常用的 4 种加密方式(MD5+Base64+SHA+BCrypt) Java 加密是指使用 Java 语言来实现数据加密、解密和数字签名等操作。数据加密是指将明文数据转换为难以理解的密文,以保护数据的机密性和完整性。Java 提供了...
包含了市面上所有常用的加密方式.zip,包含了市面上所有常用的加密方式
自动连接创建的wifi热点类,包含加密方式WPA2_PSK和WPA_PSK ,同时解决部分android手机自动连接热点导致被切换的问题,在我的前一个demo,android 解决部分手机连接热点wifi导致被切换(链接:...添加了包含了WPA2_PSK...
本项目包含了一个C#实现的各种加密方式的小工具,包含了可以直接运行的源代码以及类库文件,用户不仅可以编译这些源代码,还可以直接运行它们,从而在实际项目中应用这些加密和解密技术。 首先,我们要理解加密和...
我们将介绍四种不同的加密方式,并详细讲解每种方式的实现步骤。 首先,我们要理解批处理的基本概念。批处理文件(.bat)是包含一连串DOS命令的文本文件,这些命令在用户运行文件时按顺序执行。批处理加密的目的是...
计算机通信的课设,一种简单的数据通信加密方式的研究。
该工具包含了三种不同的加密方式,这可能包括对称加密、非对称加密以及哈希加密等方法。 对称加密是最常见的加密方式,如DES、AES等,使用同一密钥进行加密和解密,速度快,适合大量数据的加密。非对称加密,如RSA...
本篇将详细介绍三种常见的iOS加密方式:Base64编码、MD5哈希以及更高级的AES加密。 一、Base64编码 Base64是一种用于在网络上传输二进制数据的编码方式。它将任意可打印字符转换为一个特定的4字符长度的字符串,...