├── .gitmodules
├── Java
├── MagicCrypt.jar
├── javadoc
│ ├── allclasses-frame.html
│ ├── allclasses-noframe.html
│ ├── constant-values.html
│ ├── deprecated-list.html
│ ├── help-doc.html
│ ├── index-files
│ │ ├── index-1.html
│ │ ├── index-10.html
│ │ ├── index-11.html
│ │ ├── index-12.html
│ │ ├── index-13.html
│ │ ├── index-2.html
│ │ ├── index-3.html
│ │ ├── index-4.html
│ │ ├── index-5.html
│ │ ├── index-6.html
│ │ ├── index-7.html
│ │ ├── index-8.html
│ │ └── index-9.html
│ ├── index.html
│ ├── org
│ │ └── magiclen
│ │ │ └── magiccrypt
│ │ │ ├── Base64.Decoder.html
│ │ │ ├── Base64.Encoder.html
│ │ │ ├── Base64.html
│ │ │ ├── CRC64.html
│ │ │ ├── MagicCrypt.html
│ │ │ ├── Tiger.html
│ │ │ ├── Version.html
│ │ │ ├── class-use
│ │ │ ├── Base64.Decoder.html
│ │ │ ├── Base64.Encoder.html
│ │ │ ├── Base64.html
│ │ │ ├── CRC64.html
│ │ │ ├── MagicCrypt.html
│ │ │ ├── Tiger.html
│ │ │ └── Version.html
│ │ │ ├── lib
│ │ │ ├── AESCrypt.html
│ │ │ ├── CipherCrpyt.html
│ │ │ ├── Crypt.CryptListener.html
│ │ │ ├── Crypt.html
│ │ │ ├── DESCrypt.html
│ │ │ ├── class-use
│ │ │ │ ├── AESCrypt.html
│ │ │ │ ├── CipherCrpyt.html
│ │ │ │ ├── Crypt.CryptListener.html
│ │ │ │ ├── Crypt.html
│ │ │ │ └── DESCrypt.html
│ │ │ ├── package-frame.html
│ │ │ ├── package-summary.html
│ │ │ ├── package-tree.html
│ │ │ └── package-use.html
│ │ │ ├── package-frame.html
│ │ │ ├── package-summary.html
│ │ │ ├── package-tree.html
│ │ │ └── package-use.html
│ ├── overview-frame.html
│ ├── overview-summary.html
│ ├── overview-tree.html
│ ├── package-list
│ ├── script.js
│ └── stylesheet.css
└── src
│ └── org
│ └── magiclen
│ └── magiccrypt
│ ├── AwaruaTiger.java
│ ├── Base64.java
│ ├── CRC64.java
│ ├── MagicCrypt.java
│ ├── Tiger.java
│ ├── Version.java
│ ├── lib
│ ├── AESCrypt.java
│ ├── CipherCrpyt.java
│ ├── Crypt.java
│ ├── DESCrypt.java
│ └── package-info.java
│ └── package-info.java
├── PHP
├── MagicCrypt.php
└── src
│ └── MagicCrypt.php
└── README.md
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "node-magiccrypt"]
2 | path = node-magiccrypt
3 | url = git@github.com:magiclen/node-magiccrypt.git
4 | [submodule "rust-magiccrypt"]
5 | path = rust-magiccrypt
6 | url = https://github.com/magiclen/rust-magiccrypt
7 |
--------------------------------------------------------------------------------
/Java/MagicCrypt.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/magiclen/MagicCrypt/84886194877cc2f15f6aab294e0635da308be826/Java/MagicCrypt.jar
--------------------------------------------------------------------------------
/Java/javadoc/allclasses-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | All Classes
8 |
9 |
10 |
11 |
12 |
13 | All Classes
14 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/Java/javadoc/allclasses-noframe.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | All Classes
8 |
9 |
10 |
11 |
12 |
13 | All Classes
14 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/Java/javadoc/constant-values.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Constant Field Values
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 |
80 |
81 |
82 |
83 |
org.magiclen.*
84 |
85 |
86 |
87 | org.magiclen.magiccrypt.Version
88 |
89 | Modifier and Type
90 | Constant Field
91 | Value
92 |
93 |
94 |
95 |
96 |
97 | public static final int
98 | MAINTENANCE
99 | 3
100 |
101 |
102 |
103 |
104 | public static final int
105 | MAJOR
106 | 2
107 |
108 |
109 |
110 |
111 | public static final int
112 | MINOR
113 | 0
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 | org.magiclen.magiccrypt.lib.Crypt
123 |
124 | Modifier and Type
125 | Constant Field
126 | Value
127 |
128 |
129 |
130 |
131 |
132 | public static final int
133 | BUFFER_SIZE
134 | 4096
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
160 |
161 |
162 | Prev
163 | Next
164 |
165 |
169 |
172 |
173 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
--------------------------------------------------------------------------------
/Java/javadoc/deprecated-list.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Deprecated List
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 |
77 |
78 |
96 |
97 |
98 | Prev
99 | Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
--------------------------------------------------------------------------------
/Java/javadoc/index-files/index-1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | A-Index
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 | A B C D E G I K M O T V W
74 |
75 |
76 |
A
77 |
78 | AESCrypt - Class in org.magiclen.magiccrypt.lib
79 |
80 | AES CBC 128/192/256位元之加密/解密,使用PKCS5填充方式。
81 |
82 | AESCrypt(byte[], byte[]) - Constructor for class org.magiclen.magiccrypt.lib.AESCrypt
83 |
84 | 建構子。
85 |
86 |
87 |
A B C D E G I K M O T V W
88 |
89 |
107 |
134 |
135 |
136 |
137 |
--------------------------------------------------------------------------------
/Java/javadoc/index-files/index-10.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | O-Index
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 | A B C D E G I K M O T V W
74 |
75 |
76 |
O
77 |
78 | onFinished(long, long) - Method in interface org.magiclen.magiccrypt.lib.Crypt.CryptListener
79 |
80 | 加/解密結束。
81 |
82 | onRunning(long, long) - Method in interface org.magiclen.magiccrypt.lib.Crypt.CryptListener
83 |
84 | 正在進行加/解密。
85 |
86 | onStarted(long) - Method in interface org.magiclen.magiccrypt.lib.Crypt.CryptListener
87 |
88 | 開始進行加/解密。
89 |
90 | org.magiclen.magiccrypt - package org.magiclen.magiccrypt
91 |
92 | 可以在Java中快速進行加/解密。
93 |
94 | org.magiclen.magiccrypt.lib - package org.magiclen.magiccrypt.lib
95 |
96 | 用Java實作出資料加密與解密。
97 |
98 |
99 |
A B C D E G I K M O T V W
100 |
101 |
119 |
146 |
147 |
148 |
149 |
--------------------------------------------------------------------------------
/Java/javadoc/index-files/index-11.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | T-Index
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 | A B C D E G I K M O T V W
74 |
75 |
76 |
T
77 |
78 | Tiger - Class in org.magiclen.magiccrypt
79 |
80 | 計算Tiger雜奏值。
81 |
82 |
83 |
A B C D E G I K M O T V W
84 |
85 |
103 |
130 |
131 |
132 |
133 |
--------------------------------------------------------------------------------
/Java/javadoc/index-files/index-12.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | V-Index
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 | A B C D E G I K M O T V W
74 |
75 |
76 |
V
77 |
78 | Version - Class in org.magiclen.magiccrypt
79 |
80 | MagicCrypt的版本。
81 |
82 |
83 |
A B C D E G I K M O T V W
84 |
85 |
103 |
130 |
131 |
132 |
133 |
--------------------------------------------------------------------------------
/Java/javadoc/index-files/index-13.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | W-Index
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 | A B C D E G I K M O T V W
74 |
75 |
76 |
W
77 |
78 | withoutPadding() - Method in class org.magiclen.magiccrypt.Base64.Encoder
79 |
80 | Returns an encoder instance that encodes equivalently to this one,
81 | but without adding any padding character at the end of the encoded
82 | byte data.
83 |
84 | wrap(InputStream) - Method in class org.magiclen.magiccrypt.Base64.Decoder
85 |
86 | Returns an input stream for decoding
Base64
encoded byte
87 | stream.
88 |
89 | wrap(OutputStream) - Method in class org.magiclen.magiccrypt.Base64.Encoder
90 |
91 | Wraps an output stream for encoding byte data using the
92 |
Base64
encoding scheme.
93 |
94 |
95 |
A B C D E G I K M O T V W
96 |
97 |
115 |
142 |
143 |
144 |
145 |
--------------------------------------------------------------------------------
/Java/javadoc/index-files/index-2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | B-Index
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 | A B C D E G I K M O T V W
74 |
75 |
76 |
B
77 |
78 | Base64 - Class in org.magiclen.magiccrypt
79 |
80 |
81 | Clone of java.util.Base64 in Java 8 SE.
82 |
83 | Base64.Decoder - Class in org.magiclen.magiccrypt
84 |
85 | This class implements a decoder for decoding byte data using the Base64
86 | encoding scheme as specified in RFC 4648 and RFC 2045.
87 |
88 | Base64.Encoder - Class in org.magiclen.magiccrypt
89 |
90 | This class implements an encoder for encoding byte data using the Base64
91 | encoding scheme as specified in RFC 4648 and RFC 2045.
92 |
93 | BUFFER_SIZE - Static variable in class org.magiclen.magiccrypt.lib.Crypt
94 |
95 | 緩衝空間大小。
96 |
97 | byteToHexString(byte[]) - Static method in class org.magiclen.magiccrypt.MagicCrypt
98 |
99 | 講位元組陣列資料轉成16進制的字串。
100 |
101 |
102 |
A B C D E G I K M O T V W
103 |
104 |
122 |
149 |
150 |
151 |
152 |
--------------------------------------------------------------------------------
/Java/javadoc/index-files/index-3.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | C-Index
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 | A B C D E G I K M O T V W
74 |
75 |
76 |
C
77 |
78 | cipher - Variable in class org.magiclen.magiccrypt.lib.CipherCrpyt
79 |
80 | Cipher 物件。
81 |
82 | CipherCrpyt - Class in org.magiclen.magiccrypt.lib
83 |
84 | 透過Cipher來實現加/解密。
85 |
86 | CipherCrpyt() - Constructor for class org.magiclen.magiccrypt.lib.CipherCrpyt
87 |
88 | CRC64 - Class in org.magiclen.magiccrypt
89 |
90 | 計算CRC64(ECMA)雜湊值。
91 |
92 | crypt(InputStream, OutputStream, Crypt.CryptListener) - Method in class org.magiclen.magiccrypt.lib.CipherCrpyt
93 |
94 | 加/解密資料。
95 |
96 | Crypt - Class in org.magiclen.magiccrypt.lib
97 |
98 | 加/解密抽象類別,可監聽加解密過程。
99 |
100 | Crypt() - Constructor for class org.magiclen.magiccrypt.lib.Crypt
101 |
102 | Crypt.CryptListener - Interface in org.magiclen.magiccrypt.lib
103 |
104 |
105 |
A B C D E G I K M O T V W
106 |
107 |
125 |
152 |
153 |
154 |
155 |
--------------------------------------------------------------------------------
/Java/javadoc/index-files/index-7.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | I-Index
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 | A B C D E G I K M O T V W
74 |
75 |
76 |
I
77 |
78 | iv - Variable in class org.magiclen.magiccrypt.lib.CipherCrpyt
79 |
80 | 初始化向量(IV, Initialization Vector)。
81 |
82 |
83 |
A B C D E G I K M O T V W
84 |
85 |
103 |
130 |
131 |
132 |
133 |
--------------------------------------------------------------------------------
/Java/javadoc/index-files/index-8.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | K-Index
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 | A B C D E G I K M O T V W
74 |
75 |
76 |
K
77 |
78 | key - Variable in class org.magiclen.magiccrypt.lib.CipherCrpyt
79 |
80 | 加/解密的密鑰。
81 |
82 |
83 |
A B C D E G I K M O T V W
84 |
85 |
103 |
130 |
131 |
132 |
133 |
--------------------------------------------------------------------------------
/Java/javadoc/index-files/index-9.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | M-Index
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 | A B C D E G I K M O T V W
74 |
75 |
76 |
M
77 |
78 | MagicCrypt - Class in org.magiclen.magiccrypt
79 |
80 | DES/AES CBC 64/128/192/256位元之加密/解密,使用PKCS5填充方式。支援檔案、字串加密。
81 |
82 | MagicCrypt(String) - Constructor for class org.magiclen.magiccrypt.MagicCrypt
83 |
84 | 建構子,使用128位元的AES密鑰和預設IV。
85 |
86 | MagicCrypt(String, int) - Constructor for class org.magiclen.magiccrypt.MagicCrypt
87 |
88 | 建構子,使用64位元的DES密鑰,或是128位元、192位元、256位元的AES密鑰和預設IV。
89 |
90 | MagicCrypt(String, int, String) - Constructor for class org.magiclen.magiccrypt.MagicCrypt
91 |
92 |
93 | 建構子,使用64位元的DES密鑰,或是128位元、192位元、256位元的AES密鑰和自訂IV。
94 |
95 | MAINTENANCE - Static variable in class org.magiclen.magiccrypt.Version
96 |
97 | 維護版本號碼。當程式優化或是修正了一些問題,將會調整這項數值。
98 |
99 | MAJOR - Static variable in class org.magiclen.magiccrypt.Version
100 |
101 | 主版本號碼。當程式架構有了重大改變,將會調整這項數值。
102 |
103 | MINOR - Static variable in class org.magiclen.magiccrypt.Version
104 |
105 | 副版本號碼。當程式新增了功能,將會調整這項數值。
106 |
107 |
108 |
A B C D E G I K M O T V W
109 |
110 |
128 |
155 |
156 |
157 |
158 |
--------------------------------------------------------------------------------
/Java/javadoc/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Generated Documentation (Untitled)
8 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 | JavaScript is disabled on your browser.
71 |
72 | Frame Alert
73 | This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to Non-frame version .
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/Java/javadoc/org/magiclen/magiccrypt/class-use/Base64.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class org.magiclen.magiccrypt.Base64
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 |
76 | No usage of org.magiclen.magiccrypt.Base64
77 |
78 |
96 |
97 |
98 | Prev
99 | Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
--------------------------------------------------------------------------------
/Java/javadoc/org/magiclen/magiccrypt/class-use/CRC64.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class org.magiclen.magiccrypt.CRC64
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 |
76 | No usage of org.magiclen.magiccrypt.CRC64
77 |
78 |
96 |
97 |
98 | Prev
99 | Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
--------------------------------------------------------------------------------
/Java/javadoc/org/magiclen/magiccrypt/class-use/MagicCrypt.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class org.magiclen.magiccrypt.MagicCrypt
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 |
76 | No usage of org.magiclen.magiccrypt.MagicCrypt
77 |
78 |
96 |
97 |
98 | Prev
99 | Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
--------------------------------------------------------------------------------
/Java/javadoc/org/magiclen/magiccrypt/class-use/Tiger.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class org.magiclen.magiccrypt.Tiger
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 |
76 | No usage of org.magiclen.magiccrypt.Tiger
77 |
78 |
96 |
97 |
98 | Prev
99 | Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
--------------------------------------------------------------------------------
/Java/javadoc/org/magiclen/magiccrypt/class-use/Version.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class org.magiclen.magiccrypt.Version
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 |
76 | No usage of org.magiclen.magiccrypt.Version
77 |
78 |
96 |
97 |
98 | Prev
99 | Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
--------------------------------------------------------------------------------
/Java/javadoc/org/magiclen/magiccrypt/lib/class-use/AESCrypt.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class org.magiclen.magiccrypt.lib.AESCrypt
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 |
76 | No usage of org.magiclen.magiccrypt.lib.AESCrypt
77 |
78 |
96 |
97 |
98 | Prev
99 | Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
--------------------------------------------------------------------------------
/Java/javadoc/org/magiclen/magiccrypt/lib/class-use/CipherCrpyt.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class org.magiclen.magiccrypt.lib.CipherCrpyt
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 |
76 |
77 |
78 |
79 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 | Subclasses of CipherCrpyt in org.magiclen.magiccrypt.lib
103 |
104 | Modifier and Type
105 | Class and Description
106 |
107 |
108 |
109 | class
110 | AESCrypt
111 | AES CBC 128/192/256位元之加密/解密,使用PKCS5填充方式。
112 |
113 |
114 |
115 | class
116 | DESCrypt
117 | DES CBC 64位元之加密/解密,使用PKCS5填充方式。
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
146 |
147 |
148 | Prev
149 | Next
150 |
151 |
155 |
158 |
159 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
--------------------------------------------------------------------------------
/Java/javadoc/org/magiclen/magiccrypt/lib/class-use/Crypt.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class org.magiclen.magiccrypt.lib.Crypt
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 |
76 |
77 |
78 |
79 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 | Subclasses of Crypt in org.magiclen.magiccrypt.lib
103 |
104 | Modifier and Type
105 | Class and Description
106 |
107 |
108 |
109 | class
110 | AESCrypt
111 | AES CBC 128/192/256位元之加密/解密,使用PKCS5填充方式。
112 |
113 |
114 |
115 | class
116 | CipherCrpyt
117 | 透過Cipher來實現加/解密。
118 |
119 |
120 |
121 | class
122 | DESCrypt
123 | DES CBC 64位元之加密/解密,使用PKCS5填充方式。
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
152 |
153 |
154 | Prev
155 | Next
156 |
157 |
161 |
164 |
165 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
--------------------------------------------------------------------------------
/Java/javadoc/org/magiclen/magiccrypt/lib/class-use/DESCrypt.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Class org.magiclen.magiccrypt.lib.DESCrypt
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 |
76 | No usage of org.magiclen.magiccrypt.lib.DESCrypt
77 |
78 |
96 |
97 |
98 | Prev
99 | Next
100 |
101 |
105 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
--------------------------------------------------------------------------------
/Java/javadoc/org/magiclen/magiccrypt/lib/package-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | org.magiclen.magiccrypt.lib
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
Interfaces
16 |
19 |
Classes
20 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Java/javadoc/org/magiclen/magiccrypt/lib/package-summary.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | org.magiclen.magiccrypt.lib
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 |
80 |
81 |
82 |
83 |
84 | Interface Summary
85 |
86 | Interface
87 | Description
88 |
89 |
90 |
91 | Crypt.CryptListener
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 | Class Summary
100 |
101 | Class
102 | Description
103 |
104 |
105 |
106 | AESCrypt
107 |
108 | AES CBC 128/192/256位元之加密/解密,使用PKCS5填充方式。
109 |
110 |
111 |
112 | CipherCrpyt
113 |
114 | 透過Cipher來實現加/解密。
115 |
116 |
117 |
118 | Crypt
119 |
120 | 加/解密抽象類別,可監聽加解密過程。
121 |
122 |
123 |
124 | DESCrypt
125 |
126 | DES CBC 64位元之加密/解密,使用PKCS5填充方式。
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
Package org.magiclen.magiccrypt.lib Description
137 |
用Java實作出資料加密與解密。
138 |
139 |
140 |
158 |
185 |
186 |
187 |
188 |
--------------------------------------------------------------------------------
/Java/javadoc/org/magiclen/magiccrypt/lib/package-tree.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | org.magiclen.magiccrypt.lib Class Hierarchy
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 |
80 |
81 |
Class Hierarchy
82 |
83 | java.lang.Object
84 |
85 | org.magiclen.magiccrypt.lib.Crypt
86 |
87 | org.magiclen.magiccrypt.lib.CipherCrpyt
88 |
89 | org.magiclen.magiccrypt.lib.AESCrypt
90 | org.magiclen.magiccrypt.lib.DESCrypt
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
Interface Hierarchy
99 |
102 |
103 |
104 |
122 |
123 |
124 | Prev
125 | Next
126 |
127 |
131 |
134 |
135 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
--------------------------------------------------------------------------------
/Java/javadoc/org/magiclen/magiccrypt/lib/package-use.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Package org.magiclen.magiccrypt.lib
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 |
76 |
143 |
144 |
162 |
163 |
164 | Prev
165 | Next
166 |
167 |
171 |
174 |
175 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
--------------------------------------------------------------------------------
/Java/javadoc/org/magiclen/magiccrypt/package-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | org.magiclen.magiccrypt
8 |
9 |
10 |
11 |
12 |
13 |
14 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Java/javadoc/org/magiclen/magiccrypt/package-summary.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | org.magiclen.magiccrypt
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 |
80 |
81 |
82 |
83 |
84 | Class Summary
85 |
86 | Class
87 | Description
88 |
89 |
90 |
91 | Base64
92 |
93 |
94 | Clone of java.util.Base64 in Java 8 SE.
95 |
96 |
97 |
98 | Base64.Decoder
99 |
100 | This class implements a decoder for decoding byte data using the Base64
101 | encoding scheme as specified in RFC 4648 and RFC 2045.
102 |
103 |
104 |
105 | Base64.Encoder
106 |
107 | This class implements an encoder for encoding byte data using the Base64
108 | encoding scheme as specified in RFC 4648 and RFC 2045.
109 |
110 |
111 |
112 | CRC64
113 |
114 | 計算CRC64(ECMA)雜湊值。
115 |
116 |
117 |
118 | MagicCrypt
119 |
120 | DES/AES CBC 64/128/192/256位元之加密/解密,使用PKCS5填充方式。支援檔案、字串加密。
121 |
122 |
123 |
124 | Tiger
125 |
126 | 計算Tiger雜奏值。
127 |
128 |
129 |
130 | Version
131 |
132 | MagicCrypt的版本。
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
Package org.magiclen.magiccrypt Description
143 |
可以在Java中快速進行加/解密。
144 |
145 |
146 |
164 |
191 |
192 |
193 |
194 |
--------------------------------------------------------------------------------
/Java/javadoc/org/magiclen/magiccrypt/package-tree.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | org.magiclen.magiccrypt Class Hierarchy
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 |
80 |
81 |
Class Hierarchy
82 |
83 | java.lang.Object
84 |
93 |
94 |
95 |
96 |
97 |
115 |
116 |
117 | Prev
118 | Next
119 |
120 |
124 |
127 |
128 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
--------------------------------------------------------------------------------
/Java/javadoc/org/magiclen/magiccrypt/package-use.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Uses of Package org.magiclen.magiccrypt
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 |
76 |
77 |
78 |
79 |
94 |
95 |
96 |
97 |
98 |
99 | Classes in org.magiclen.magiccrypt used by org.magiclen.magiccrypt
100 |
101 | Class and Description
102 |
103 |
104 |
105 | Base64.Decoder
106 | This class implements a decoder for decoding byte data using the Base64
107 | encoding scheme as specified in RFC 4648 and RFC 2045.
108 |
109 |
110 |
111 | Base64.Encoder
112 | This class implements an encoder for encoding byte data using the Base64
113 | encoding scheme as specified in RFC 4648 and RFC 2045.
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
140 |
141 |
142 | Prev
143 | Next
144 |
145 |
149 |
152 |
153 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
--------------------------------------------------------------------------------
/Java/javadoc/overview-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Overview List
8 |
9 |
10 |
11 |
12 |
13 |
14 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Java/javadoc/overview-summary.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Overview
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 |
96 |
97 |
115 |
116 |
117 | Prev
118 | Next
119 |
120 |
124 |
127 |
128 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
--------------------------------------------------------------------------------
/Java/javadoc/overview-tree.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Class Hierarchy
8 |
9 |
10 |
11 |
12 |
13 |
23 |
24 | JavaScript is disabled on your browser.
25 |
26 |
27 |
45 |
72 |
73 |
81 |
82 |
Class Hierarchy
83 |
84 | java.lang.Object
85 |
86 | org.magiclen.magiccrypt.Base64
87 | org.magiclen.magiccrypt.Base64.Decoder
88 | org.magiclen.magiccrypt.Base64.Encoder
89 | org.magiclen.magiccrypt.CRC64
90 | org.magiclen.magiccrypt.lib.Crypt
91 |
92 | org.magiclen.magiccrypt.lib.CipherCrpyt
93 |
94 | org.magiclen.magiccrypt.lib.AESCrypt
95 | org.magiclen.magiccrypt.lib.DESCrypt
96 |
97 |
98 |
99 |
100 | org.magiclen.magiccrypt.MagicCrypt
101 | org.magiclen.magiccrypt.Tiger
102 | org.magiclen.magiccrypt.Version
103 |
104 |
105 |
106 |
Interface Hierarchy
107 |
110 |
111 |
112 |
130 |
131 |
132 | Prev
133 | Next
134 |
135 |
139 |
142 |
143 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
--------------------------------------------------------------------------------
/Java/javadoc/package-list:
--------------------------------------------------------------------------------
1 | org.magiclen.magiccrypt
2 | org.magiclen.magiccrypt.lib
3 |
--------------------------------------------------------------------------------
/Java/javadoc/script.js:
--------------------------------------------------------------------------------
1 | function show(type)
2 | {
3 | count = 0;
4 | for (var key in methods) {
5 | var row = document.getElementById(key);
6 | if ((methods[key] & type) != 0) {
7 | row.style.display = '';
8 | row.className = (count++ % 2) ? rowColor : altColor;
9 | }
10 | else
11 | row.style.display = 'none';
12 | }
13 | updateTabs(type);
14 | }
15 |
16 | function updateTabs(type)
17 | {
18 | for (var value in tabs) {
19 | var sNode = document.getElementById(tabs[value][0]);
20 | var spanNode = sNode.firstChild;
21 | if (value == type) {
22 | sNode.className = activeTableTab;
23 | spanNode.innerHTML = tabs[value][1];
24 | }
25 | else {
26 | sNode.className = tableTab;
27 | spanNode.innerHTML = "" + tabs[value][1] + " ";
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Java/src/org/magiclen/magiccrypt/CRC64.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright 2015-2018 magiclen.org
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | *
17 | */
18 | package org.magiclen.magiccrypt;
19 |
20 | /**
21 | * 計算CRC64(ECMA)雜湊值。
22 | *
23 | * @author Magic Len
24 | */
25 | public class CRC64 {
26 |
27 | // -----類別常數-----
28 | private static final long POLY64REV = 0x42F0E1EBA9EA3693L;
29 | private static final long[] LOOKUPTABLE = new long[256];
30 |
31 | // -----類別初始-----
32 | static {
33 | final long mask1 = 1L << 63;
34 | long mask2 = 1;
35 | for (int i = 1; i < 64; ++i) {
36 | mask2 = (mask2 << 1) + 1;
37 | }
38 | for (int i = 0; i < 256; ++i) {
39 | long v = i;
40 | for (int j = 0; j < 64; ++j) {
41 | if ((v & mask1) == 0) {
42 | v = v << 1;
43 | } else {
44 | v = v << 1;
45 | v = v ^ POLY64REV;
46 | }
47 | }
48 | LOOKUPTABLE[i] = v & mask2;
49 | }
50 | }
51 |
52 | // -----類別方法-----
53 | /**
54 | * 取得資料的CRC64雜湊值。
55 | *
56 | * @param data 傳入要雜湊的資料
57 | * @return 傳回雜湊後資料內容
58 | */
59 | public static byte[] getHash(final byte[] data) {
60 | if (data == null) {
61 | return null;
62 | }
63 | long sum = ~0;
64 | for (final byte b : data) {
65 | final int lookupidx = (int) (((sum >>> 56) ^ b) & 0xff);
66 | sum = (sum << 8) ^ LOOKUPTABLE[lookupidx];
67 | }
68 | sum = sum ^ ~0;
69 | final byte[] crc64 = new byte[8];
70 | crc64[0] = (byte) (sum >>> 56);
71 | crc64[1] = (byte) ((sum << 8) >>> 56);
72 | crc64[2] = (byte) ((sum << 16) >>> 56);
73 | crc64[3] = (byte) ((sum << 24) >>> 56);
74 | crc64[4] = (byte) ((sum << 32) >>> 56);
75 | crc64[5] = (byte) ((sum << 40) >>> 56);
76 | crc64[6] = (byte) ((sum << 48) >>> 56);
77 | crc64[7] = (byte) ((sum << 56) >>> 56);
78 | return crc64;
79 | }
80 |
81 | // -----建構子-----
82 | /**
83 | * 私有建構子,無法給外界實體化。
84 | */
85 | private CRC64() {
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/Java/src/org/magiclen/magiccrypt/Tiger.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright 2015-2018 magiclen.org
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | *
17 | */
18 | package org.magiclen.magiccrypt;
19 |
20 | /**
21 | * 計算Tiger雜奏值。
22 | *
23 | * @author Magic Len
24 | */
25 | public class Tiger {
26 |
27 | // -----類別方法-----
28 | /**
29 | * 取得資料的Tiger雜湊值。
30 | *
31 | * @param data 傳入要雜湊的資料
32 | * @return 傳回雜湊後資料內容
33 | */
34 | public static byte[] getHash(final byte[] data) {
35 | if (data == null) {
36 | return null;
37 | }
38 | final AwaruaTiger tiger = new AwaruaTiger();
39 | return tiger.ComputeHash(data);
40 | }
41 |
42 | // -----建構子-----
43 | /**
44 | * 私有建構子,無法給外界實體化。
45 | */
46 | private Tiger() {
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Java/src/org/magiclen/magiccrypt/Version.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright 2015-2018 magiclen.org
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | *
17 | */
18 | package org.magiclen.magiccrypt;
19 |
20 | /**
21 | * MagicCrypt的版本。
22 | *
23 | * @author Magic Len
24 | */
25 | public final class Version {
26 |
27 | /**
28 | * 主版本號碼。當程式架構有了重大改變,將會調整這項數值。
29 | */
30 | public static final int MAJOR = 2;
31 | /**
32 | * 副版本號碼。當程式新增了功能,將會調整這項數值。
33 | */
34 | public static final int MINOR = 0;
35 | /**
36 | * 維護版本號碼。當程式優化或是修正了一些問題,將會調整這項數值。
37 | */
38 | public static final int MAINTENANCE = 3;
39 |
40 | /**
41 | * 私有的建構子,將無法被實體化。
42 | */
43 | private Version() {
44 |
45 | }
46 |
47 | /**
48 | * 取得版本字串。
49 | *
50 | * @return 傳回版本字串
51 | */
52 | public static String getVersion() {
53 | return String.format("%d.%d.%d", MAJOR, MINOR, MAINTENANCE);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/Java/src/org/magiclen/magiccrypt/lib/AESCrypt.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright 2015-2018 magiclen.org
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | *
17 | */
18 | package org.magiclen.magiccrypt.lib;
19 |
20 | import javax.crypto.Cipher;
21 | import javax.crypto.spec.IvParameterSpec;
22 | import javax.crypto.spec.SecretKeySpec;
23 |
24 | /**
25 | * AES CBC 128/192/256位元之加密/解密,使用PKCS5填充方式。
26 | *
27 | * @author Magic Len
28 | */
29 | public class AESCrypt extends CipherCrpyt {
30 |
31 | // -----建構子-----
32 | /**
33 | * 建構子。
34 | *
35 | * @param key 傳入16位元組(128位元)、24位元組(192位元)或是32位元組(256位元)的密鑰
36 | * @param iv 傳入16位元組(128位元)的初始化向量
37 | */
38 | public AESCrypt(final byte[] key, final byte[] iv) {
39 | if (key == null || iv == null) {
40 | throw new RuntimeException("Need a key and an initialization vector to construct an AESCrypt object!");
41 | }
42 |
43 | final int keyLength = key.length;
44 | if (keyLength != 16 && keyLength != 24 && keyLength != 32) {
45 | throw new RuntimeException("The AES key must be 16 bytes(128 bits), 24 bytes(192 bits) or 32 bytes(256 bits)!");
46 | }
47 |
48 | final int ivLength = iv.length;
49 | if (ivLength != 16) {
50 | throw new RuntimeException("The IV must be 16 bytes(128 bits)!");
51 | }
52 |
53 | this.key = new SecretKeySpec(key, "AES");
54 | this.iv = new IvParameterSpec(iv);
55 |
56 | init();
57 | }
58 |
59 | // -----物件方法-----
60 | /**
61 | * 初始化。
62 | */
63 | private void init() {
64 | try {
65 | cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
66 | } catch (final Exception ex) {
67 | throw new RuntimeException(ex.getMessage());
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Java/src/org/magiclen/magiccrypt/lib/CipherCrpyt.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright 2015-2018 magiclen.org
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | *
17 | */
18 | package org.magiclen.magiccrypt.lib;
19 |
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.io.OutputStream;
23 | import java.security.Key;
24 | import javax.crypto.Cipher;
25 | import javax.crypto.CipherOutputStream;
26 | import javax.crypto.spec.IvParameterSpec;
27 | import static org.magiclen.magiccrypt.lib.Crypt.BUFFER_SIZE;
28 |
29 | /**
30 | * 透過Cipher來實現加/解密。
31 | *
32 | * @author Magic Len
33 | */
34 | public abstract class CipherCrpyt extends Crypt {
35 |
36 | // -----物件變數-----
37 | /**
38 | * 加/解密的密鑰。
39 | */
40 | protected Key key;
41 | /**
42 | * 初始化向量(IV, Initialization Vector)。
43 | */
44 | protected IvParameterSpec iv;
45 | /**
46 | * Cipher 物件。
47 | */
48 | protected Cipher cipher;
49 |
50 | // -----物件方法-----
51 | /**
52 | * 加/解密資料。
53 | *
54 | * @param inputData 傳入輸入的資料流
55 | * @param outputData 傳入輸出的資料流
56 | * @param listener 傳入監聽者物件
57 | * @throws java.io.IOException 當輸入輸出處理時發生問題,會拋出這個例外
58 | */
59 | protected void crypt(final InputStream inputData, final OutputStream outputData, final Crypt.CryptListener listener) throws IOException {
60 | final int totalBytes = inputData.available();
61 |
62 | if (listener != null) {
63 | listener.onStarted(totalBytes);
64 | }
65 |
66 | long sum = 0;
67 | try (final CipherOutputStream cos = new CipherOutputStream(outputData, cipher)) {
68 | int c;
69 | final byte[] buffer = new byte[BUFFER_SIZE];
70 | while ((c = inputData.read(buffer)) >= 0) {
71 | cos.write(buffer, 0, c);
72 | if (c > 0) {
73 | sum += c;
74 | }
75 | if (listener != null) {
76 | if (!listener.onRunning(sum, (sum > totalBytes) ? -1 : totalBytes)) {
77 | break;
78 | }
79 | }
80 | }
81 | inputData.close();
82 | cos.flush();
83 | }
84 | if (listener != null) {
85 | listener.onFinished(sum, totalBytes);
86 | }
87 | }
88 |
89 | /**
90 | * 加密資料。
91 | *
92 | * @param inputData 傳入要加密的資料流
93 | * @param outputData 傳入已加密的資料流
94 | * @param listener 傳入監聽者物件
95 | * @throws java.io.IOException 當輸入輸出處理時發生問題,會拋出這個例外
96 | */
97 | @Override
98 | public void encrypt(final InputStream inputData, final OutputStream outputData, final Crypt.CryptListener listener) throws IOException {
99 | try {
100 | cipher.init(Cipher.ENCRYPT_MODE, key, iv);
101 | crypt(inputData, outputData, listener);
102 | } catch (final IOException ex) {
103 | throw ex;
104 | } catch (final Exception ex) {
105 | throw new RuntimeException(ex.getMessage());
106 | }
107 | }
108 |
109 | /**
110 | * 解密資料。
111 | *
112 | * @param inputData 傳入要解密的資料流
113 | * @param outputData 傳入已解密的資料流
114 | * @param listener 傳入監聽者物件
115 | * @throws java.io.IOException 當輸入輸出處理時發生問題,會拋出這個例外
116 | */
117 | @Override
118 | public void decrypt(final InputStream inputData, final OutputStream outputData, final Crypt.CryptListener listener) throws IOException {
119 | try {
120 | cipher.init(Cipher.DECRYPT_MODE, key, iv);
121 | crypt(inputData, outputData, listener);
122 | } catch (final IOException ex) {
123 | throw ex;
124 | } catch (final Exception ex) {
125 | throw new RuntimeException(ex.getMessage());
126 | }
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/Java/src/org/magiclen/magiccrypt/lib/Crypt.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright 2015-2018 magiclen.org
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | *
17 | */
18 | package org.magiclen.magiccrypt.lib;
19 |
20 | import java.io.ByteArrayInputStream;
21 | import java.io.ByteArrayOutputStream;
22 | import java.io.IOException;
23 | import java.io.InputStream;
24 | import java.io.OutputStream;
25 |
26 | /**
27 | * 加/解密抽象類別,可監聽加解密過程。
28 | *
29 | * @author Magic Len
30 | */
31 | public abstract class Crypt {
32 |
33 | // -----類別介面-----
34 | public static interface CryptListener {
35 |
36 | /**
37 | * 開始進行加/解密。
38 | *
39 | * @param totalBytes 要處理的資料大小
40 | */
41 | public void onStarted(final long totalBytes);
42 |
43 | /**
44 | * 正在進行加/解密。
45 | *
46 | * @param currentBytes 目前已處理的資料大小
47 | * @param totalBytes 全部的資料大小
48 | * @return 傳回是否要繼續處理資料
49 | */
50 | public boolean onRunning(final long currentBytes, final long totalBytes);
51 |
52 | /**
53 | * 加/解密結束。
54 | *
55 | * @param finishedBytes 已處理的資料大小
56 | * @param totalBytes 全部的資料大小
57 | */
58 | public void onFinished(final long finishedBytes, final long totalBytes);
59 | }
60 |
61 | // -----類別常數-----
62 | /**
63 | * 緩衝空間大小。
64 | */
65 | public static final int BUFFER_SIZE = 4096;
66 |
67 | // -----物件變數-----
68 | // -----物件方法-----
69 | /**
70 | * 加密資料。
71 | *
72 | * @param data 傳入要加密的資料
73 | * @return 傳回加密後的資料
74 | */
75 | public byte[] encrypt(final byte[] data) {
76 | return encrypt(data, null);
77 | }
78 |
79 | /**
80 | * 加密資料。
81 | *
82 | * @param data 傳入要加密的資料
83 | * @param listener 傳入監聽者物件
84 | * @return 傳回加密後的資料
85 | */
86 | public byte[] encrypt(final byte[] data, final CryptListener listener) {
87 | try (final ByteArrayInputStream bais = new ByteArrayInputStream(data); final ByteArrayOutputStream baos = new ByteArrayOutputStream();) {
88 | encrypt(bais, baos, listener);
89 | return baos.toByteArray();
90 | } catch (final Exception ex) {
91 | throw new RuntimeException(ex.getMessage());
92 | }
93 | }
94 |
95 | /**
96 | * 解密資料。
97 | *
98 | * @param data 傳入要解密的資料
99 | * @return 傳回解密後的資料
100 | */
101 | public byte[] decrypt(final byte[] data) {
102 | return decrypt(data, null);
103 | }
104 |
105 | /**
106 | * 解密資料。
107 | *
108 | * @param data 傳入要解密的資料
109 | * @param listener 傳入監聽者物件
110 | * @return 傳回加密後的資料
111 | */
112 | public byte[] decrypt(final byte[] data, final CryptListener listener) {
113 | try (final ByteArrayInputStream bais = new ByteArrayInputStream(data); final ByteArrayOutputStream baos = new ByteArrayOutputStream();) {
114 | decrypt(bais, baos, listener);
115 | return baos.toByteArray();
116 | } catch (final Exception ex) {
117 | throw new RuntimeException(ex.getMessage());
118 | }
119 | }
120 |
121 | /**
122 | * 加密資料。
123 | *
124 | * @param inputData 傳入要加密的資料流
125 | * @param outputData 傳入已加密的資料流
126 | * @throws java.io.IOException 當輸入輸出處理時發生問題,會拋出這個例外
127 | */
128 | public void encrypt(final InputStream inputData, final OutputStream outputData) throws IOException {
129 | encrypt(inputData, outputData, null);
130 | }
131 |
132 | /**
133 | * 解密資料。
134 | *
135 | * @param inputData 傳入要解密的資料流
136 | * @param outputData 傳入已解密的資料流
137 | * @throws java.io.IOException 當輸入輸出處理時發生問題,會拋出這個例外
138 | */
139 | public void decrypt(final InputStream inputData, final OutputStream outputData) throws IOException {
140 | decrypt(inputData, outputData, null);
141 | }
142 |
143 | // -----抽象方法-----
144 | /**
145 | * 加密資料。
146 | *
147 | * @param inputData 傳入要加密的資料流
148 | * @param outputData 傳入已加密的資料流
149 | * @param listener 傳入監聽者物件
150 | * @throws java.io.IOException 當輸入輸出處理時發生問題,會拋出這個例外
151 | */
152 | public abstract void encrypt(final InputStream inputData, final OutputStream outputData, final CryptListener listener) throws IOException;
153 |
154 | /**
155 | * 解密資料。
156 | *
157 | * @param inputData 傳入要解密的資料流
158 | * @param outputData 傳入已解密的資料流
159 | * @param listener 傳入監聽者物件
160 | * @throws java.io.IOException 當輸入輸出處理時發生問題,會拋出這個例外
161 | */
162 | public abstract void decrypt(final InputStream inputData, final OutputStream outputData, final CryptListener listener) throws IOException;
163 | }
164 |
--------------------------------------------------------------------------------
/Java/src/org/magiclen/magiccrypt/lib/DESCrypt.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright 2015-2018 magiclen.org
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | *
17 | */
18 | package org.magiclen.magiccrypt.lib;
19 |
20 | import javax.crypto.Cipher;
21 | import javax.crypto.spec.IvParameterSpec;
22 | import javax.crypto.spec.SecretKeySpec;
23 |
24 | /**
25 | * DES CBC 64位元之加密/解密,使用PKCS5填充方式。
26 | *
27 | * @author Magic Len
28 | */
29 | public class DESCrypt extends CipherCrpyt {
30 |
31 | // -----建構子-----
32 | /**
33 | * 建構子。
34 | *
35 | * @param key 傳入8位元組(64位元)的密鑰
36 | * @param iv 傳入8位元組(64位元)的初始化向量
37 | */
38 | public DESCrypt(final byte[] key, final byte[] iv) {
39 | if (key == null || iv == null) {
40 | throw new RuntimeException("Need a key and an initialization vector to construct an DESCrypt object!");
41 | }
42 |
43 | final int keyLength = key.length;
44 | if (keyLength != 8) {
45 | throw new RuntimeException("The DES key must be 8 bytes(64 bits)!");
46 | }
47 |
48 | final int ivLength = iv.length;
49 | if (ivLength != 8) {
50 | throw new RuntimeException("The IV must be 8 bytes(64 bits)!");
51 | }
52 |
53 | this.key = new SecretKeySpec(key, "DES");
54 | this.iv = new IvParameterSpec(iv);
55 |
56 | init();
57 | }
58 |
59 | // -----物件方法-----
60 | /**
61 | * 初始化。
62 | */
63 | private void init() {
64 | try {
65 | cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
66 | } catch (final Exception ex) {
67 | throw new RuntimeException(ex.getMessage());
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Java/src/org/magiclen/magiccrypt/lib/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright 2015-20178 magiclen.org
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | *
17 | */
18 | /**
19 | * 用Java實作出資料加密與解密。
20 | */
21 | package org.magiclen.magiccrypt.lib;
22 |
--------------------------------------------------------------------------------
/Java/src/org/magiclen/magiccrypt/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright 2015-2018 magiclen.org
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | *
17 | */
18 | /**
19 | * 可以在Java中快速進行加/解密。
20 | */
21 | package org.magiclen.magiccrypt;
22 |
--------------------------------------------------------------------------------
/PHP/MagicCrypt.php:
--------------------------------------------------------------------------------
1 | key=MagicCrypt::crc64($key);if($iv!=''){$this->iv=MagicCrypt::crc64($iv);}else{$this->iv=chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0);}}break;case 128:case 192:case 256:{switch($bit){case 128:$this->key=hash('MD5',$key,true);break;case 192:$this->key=hash('tiger192,3',$key,true);break;case 256:$this->key=hash('SHA256',$key,true);break;}if($iv!=''){$this->iv=hash('MD5',$iv,true);}else{$this->iv=chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0);}}break;default:throw new \Exception('The key must be 8 bytes(64 bits), 16 bytes(128 bits), 24 bytes(192 bits) or 32 bytes(256 bits)!');}$this->bit=$bit;}public function encrypt($str){$algorithm=$this->bit>64?MCRYPT_RIJNDAEL_128:'des';$module=mcrypt_module_open($algorithm,'',MCRYPT_MODE_CBC,'');mcrypt_generic_init($module,$this->key,$this->iv);$block=mcrypt_get_block_size($algorithm,MCRYPT_MODE_CBC);$pad=$block -(strlen($str)% $block);$str.=str_repeat(chr($pad),$pad);$encrypted=mcrypt_generic($module,$str);mcrypt_generic_deinit($module);mcrypt_module_close($module);return base64_encode($encrypted);}public function decrypt($str){$algorithm=$this->bit>64?MCRYPT_RIJNDAEL_128:'des';$module=mcrypt_module_open($algorithm,'',MCRYPT_MODE_CBC,'');mcrypt_generic_init($module,$this->key,$this->iv);$str=mdecrypt_generic($module,base64_decode($str));mcrypt_generic_deinit($module);mcrypt_module_close($module);$slast=ord(substr($str,-1));$str=substr($str,0,strlen($str)- $slast);return $str;}private static function crc64Table(){$crc64tab=[];$poly64rev=(0x42F0E1EB << 32)| 0xA9EA3693;$mask1=1 << 63;$mask2=1;for($i=1;$i<64;++$i){$mask2=($mask2 << 1)+ 1;}for($i=0;$i<256;++$i){$v=$i;for($j=0;$j<64;++$j){if(($v & $mask1)==0){$v=$v << 1;}else{$v=$v << 1;$v=$v ^ $poly64rev;}}$crc64tab[$i]=$v & $mask2;}return $crc64tab;}private static function crc64($string){static $crc64tab;if($crc64tab===null){$crc64tab=MagicCrypt::crc64Table();}$h8Mask=~(0xff << 56);$crc=~0;$length=strlen($string);for($i=0;$i<$length;++$i){$lookupidx=((($crc >> 56)& $h8Mask)^ ord($string[$i]))& 0xff;$crc=($crc << 8)^ $crc64tab[$lookupidx];}$crc=$crc ^ ~0;return pack('CCCCCCCC',($crc >> 56)& $h8Mask,(($crc << 8)>> 56)& $h8Mask,(($crc << 16)>> 56)& $h8Mask,(($crc << 24)>> 56)& $h8Mask,(($crc << 32)>> 56)& $h8Mask,(($crc << 40)>> 56)& $h8Mask,(($crc << 48)>> 56)& $h8Mask,(($crc << 56)>> 56)& $h8Mask);}}?>
2 |
--------------------------------------------------------------------------------
/PHP/src/MagicCrypt.php:
--------------------------------------------------------------------------------
1 | key = MagicCrypt::crc64($key);
30 | if($iv != ''){
31 | $this->iv = MagicCrypt::crc64($iv);
32 | }else{
33 | $this->iv = chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0); //IV is not set. It doesn't recommend.
34 | }
35 | }
36 | break;
37 | case 128:
38 | case 192:
39 | case 256: {
40 | switch ($bit) {
41 | case 128:
42 | $this->key = hash('MD5', $key, true);
43 | break;
44 | case 192:
45 | $this->key = hash('tiger192,3', $key, true);
46 | break;
47 | case 256:
48 | $this->key = hash('SHA256', $key, true);
49 | break;
50 | }
51 | if($iv != ''){
52 | $this->iv = hash('MD5', $iv, true);
53 | }else{
54 | $this->iv = chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0).chr(0); //IV is not set. It doesn't recommend.
55 | }
56 | }
57 | break;
58 | default:
59 | throw new \Exception('The key must be 8 bytes(64 bits), 16 bytes(128 bits), 24 bytes(192 bits) or 32 bytes(256 bits)!');
60 | }
61 | $this->bit = $bit;
62 | }
63 |
64 | public function encrypt($str) {
65 | $algorithm = $this->bit > 64 ? MCRYPT_RIJNDAEL_128 : 'des';
66 | //Open
67 | $module = mcrypt_module_open($algorithm, '', MCRYPT_MODE_CBC, '');
68 | mcrypt_generic_init($module, $this->key, $this->iv);
69 |
70 | //Padding
71 | $block = mcrypt_get_block_size($algorithm, MCRYPT_MODE_CBC); //Get Block Size
72 | $pad = $block - (strlen($str) % $block); //Compute how many characters need to pad
73 | $str .= str_repeat(chr($pad), $pad); // After pad, the str length must be equal to block or its integer multiples
74 |
75 | //Encrypt
76 | $encrypted = mcrypt_generic($module, $str);
77 |
78 | //Close
79 | mcrypt_generic_deinit($module);
80 | mcrypt_module_close($module);
81 |
82 | //Return
83 | return base64_encode($encrypted);
84 | }
85 |
86 | public function decrypt($str) {
87 | $algorithm = $this->bit > 64 ? MCRYPT_RIJNDAEL_128 : 'des';
88 | //Open
89 | $module = mcrypt_module_open($algorithm, '', MCRYPT_MODE_CBC, '');
90 | mcrypt_generic_init($module, $this->key, $this->iv);
91 |
92 | //Decrypt
93 | $str = mdecrypt_generic($module, base64_decode($str)); //Get original str
94 |
95 | //Close
96 | mcrypt_generic_deinit($module);
97 | mcrypt_module_close($module);
98 |
99 | //Depadding
100 | $slast = ord(substr($str, -1)); //pad value and pad count
101 | $str = substr($str, 0, strlen($str) - $slast);
102 |
103 | //Return
104 | return $str;
105 | }
106 |
107 | private static function crc64Table() {
108 | $crc64tab = [];
109 | $poly64rev = (0x42F0E1EB << 32) | 0xA9EA3693;
110 |
111 | $mask1 = 1 << 63;
112 | $mask2 = 1;
113 | for ($i = 1; $i < 64; ++$i) {
114 | $mask2 = ($mask2 << 1) + 1;
115 | }
116 |
117 | for ($i = 0; $i < 256; ++$i) {
118 | $v = $i;
119 | for ($j = 0; $j < 64; ++$j) {
120 | if (($v & $mask1) == 0) {
121 | $v = $v << 1;
122 | } else {
123 | $v = $v << 1;
124 | $v = $v ^ $poly64rev;
125 | }
126 | }
127 | $crc64tab[$i] = $v & $mask2;
128 | }
129 |
130 | return $crc64tab;
131 | }
132 |
133 | private static function crc64($string) {
134 | static $crc64tab;
135 | if ($crc64tab === null) {
136 | $crc64tab = MagicCrypt::crc64Table();
137 | }
138 |
139 | $h8Mask = ~(0xff << 56);
140 |
141 | $crc = ~0;
142 | $length = strlen($string);
143 | for ($i = 0; $i < $length; ++$i) {
144 | $lookupidx = ((($crc >> 56) & $h8Mask) ^ ord($string[$i])) & 0xff;
145 | $crc = ($crc << 8) ^ $crc64tab[$lookupidx];
146 | }
147 | $crc = $crc ^ ~0;
148 |
149 | return pack('CCCCCCCC', ($crc >> 56) & $h8Mask, (($crc << 8) >> 56) & $h8Mask, (($crc << 16) >> 56) & $h8Mask, (($crc << 24) >> 56) & $h8Mask, (($crc << 32) >> 56) & $h8Mask, (($crc << 40) >> 56) & $h8Mask, (($crc << 48) >> 56) & $h8Mask, (($crc << 56) >> 56) & $h8Mask);
150 | }
151 | }
152 | ?>
153 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | MagicCrypt
2 | =================================
3 |
4 | # Introduction
5 |
6 | **MagicCrypt** is a Java/PHP/NodeJS/Rust library to encrypt/decrpyt strings, files, or data, using Data Encryption Standard(DES) or Advanced Encryption Standard(AES) algorithms. It supports `CBC` block cipher mode, `PKCS5` padding and 64, 128, 192 or 256-bits key length. If the encrypted data is a string, it will be formatted automatically to Base64.
7 |
8 | # Usage For Java
9 |
10 | ## MagicCrypt Class
11 |
12 | **MagicCrypt** class is in the *org.magiclen.magiccrypt* package. It can help you encrypt/decrpyt strings, files, or data, using Data Encryption Standard(DES) or Advanced Encryption Standard(AES) algorithms.
13 |
14 | ### Initialize
15 |
16 | You have to input your DES/AES key and key length to construct **MagicCrypt** object. For example,
17 |
18 | ```java
19 | final MagicCrypt mc = new MagicCrypt("magickey", 256);
20 | ```
21 |
22 | Note. **MagicCrypt** only supports 64(DES), 128, 192 and 256-bits key length. The larger key length, the stronger security of course. The default length is 128 bits. If you want to use 192 or 256 bits in your Java Runtime Machine (JRE), you have to install Java Cryptography Extension (JCE) first.
23 |
24 | By the way, if you want to change Initialization Vector(IV), you can set it by passing your IV string into the third parameter to the constructor of **MagicCrypt** object.
25 |
26 | ### Encrypt
27 |
28 | You can use **encrypt** method to encrypt any string, file, or data. For example,
29 |
30 | ```java
31 | final MagicCrypt mc = new MagicCrypt("magickey", 256);
32 | System.out.println(mc.encrypt("http://magiclen.org"));
33 | ```
34 |
35 | The result is,
36 |
37 | ```
38 | DS/2U8royDnJDiNY2ps3f6ZoTbpZo8ZtUGYLGEjwLDQ=
39 | ```
40 |
41 | ### Decrypt
42 |
43 | You can use **decrypt** method to decrypt any encrypted string or data. For example,
44 |
45 | ```java
46 | final MagicCrypt mc = new MagicCrypt("magickey", 256);
47 | System.out.println(mc.decrypt("DS/2U8royDnJDiNY2ps3f6ZoTbpZo8ZtUGYLGEjwLDQ="));
48 | ```
49 |
50 | The result is,
51 |
52 | ```
53 | http://magiclen.org
54 | ```
55 |
56 | ### Listener
57 |
58 | If you want to observe the progress when MagicCrypt is running. You can add your listener object which implemented the interface **CryptListener** in the **Crypt** class in the *org.magiclen.magiccrypt.lib* package to **MagicCrypt**'s **encrypt** or **decrypt** method as a parameter.
59 |
60 | For example, if you want to encrypt a file, you can write the code as below,
61 |
62 | ```java
63 | final File from = new File("/home/magiclen/plainFile");
64 | final File to = new File("/home/magiclen/encryptedFile");
65 | final MagicCrypt mc = new MagicCrypt("magickey", 192);
66 | mc.encrypt(from, to, new Crypt.CryptListener() {
67 | @Override
68 | public void onStarted(final long totalBytes) {
69 | }
70 |
71 | @Override
72 | public boolean onRunning(final long currentBytes, final long totalBytes) {
73 | return true; // return false to stop
74 | }
75 |
76 | @Override
77 | public void onFinished(final long finishedBytes, final long totalBytes) {
78 | }
79 | });
80 | ```
81 |
82 | ## Base64 Class
83 |
84 | **Base64** class is in the *org.magiclen.magiccrypt* package. It is a clone of an implementation of Base64 in Java 8 SE adjusted for the old Java versions lower than 8.
85 |
86 | # Usage For PHP
87 |
88 | ## MagicCrypt.php
89 |
90 | ### Initialize
91 |
92 | `require` of `include` **MagicCrypt.php** into your PHP program. Then, you have to input your DES/AES key and key length to construct **MagicCrypt** object. For example,
93 |
94 | ```php
95 | require('MagicCrypt.php');
96 | use org\magiclen\magiccrypt\MagicCrypt;
97 |
98 | $mc = new MagicCrypt('magickey', 256);
99 | ```
100 |
101 | If you want to change Initialization Vector(IV), you can set it by passing your IV string into the third parameter to the constructor of **MagicCrypt** object.
102 |
103 | ### Encrypt
104 |
105 | You can use **encrypt** method to encrypt any string. For example,
106 |
107 | ```php
108 | $mc = new MagicCrypt('magickey', 256);
109 | echo $mc->encrypt('http://magiclen.org');
110 | ```
111 |
112 | The result is,
113 |
114 | ```
115 | DS/2U8royDnJDiNY2ps3f6ZoTbpZo8ZtUGYLGEjwLDQ=
116 | ```
117 |
118 | ### Decrypt
119 |
120 | You can use **decrypt** method to decrypt any encrypted string. For example,
121 |
122 | ```php
123 | $mc = new MagicCrypt('magickey', 256);
124 | echo $mc->decrypt('DS/2U8royDnJDiNY2ps3f6ZoTbpZo8ZtUGYLGEjwLDQ=');
125 | ```
126 |
127 | The result is,
128 |
129 | ```
130 | http://magiclen.org
131 | ```
132 |
133 | # Usage For Node.js
134 |
135 | Refer to https://github.com/magiclen/node-magiccrypt
136 |
137 | # Usage For Rust
138 |
139 | Refer to https://github.com/magiclen/node-magiccrypt
140 |
141 | # License
142 |
143 | ```
144 | Copyright 2015-2018 magiclen.org
145 |
146 | Licensed under the Apache License, Version 2.0 (the "License");
147 | you may not use this file except in compliance with the License.
148 | You may obtain a copy of the License at
149 |
150 | http://www.apache.org/licenses/LICENSE-2.0
151 |
152 | Unless required by applicable law or agreed to in writing, software
153 | distributed under the License is distributed on an "AS IS" BASIS,
154 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
155 | See the License for the specific language governing permissions and
156 | limitations under the License.
157 | ```
158 |
159 | # What's More?
160 |
161 | Please check out our web page at
162 |
163 | https://magiclen.org/aes/
164 |
--------------------------------------------------------------------------------