MCPcopy Index your code
hub / github.com/f0ng/autoDecoder / padding

Method padding

src/com/autoDecoder/util/SM4.java:168–211  ·  view source on GitHub ↗
(byte[] input, int mode)

Source from the content-addressed store, hash-verified

166 }
167 //修改了填充模式,为模式
168 private byte[] padding(byte[] input, int mode) {
169 if (input == null) {
170 return null;
171 }
172
173 byte[] ret = (byte[]) null;
174 if (mode == SM4_ENCRYPT) {
175 //填充:hex必须是32的整数倍填充 ,填充的是80 00 00 00
176 int p = 16 - input.length % 16;
177 String inputHex = Util.byteToHex(input)+ "80";
178// System.out.println(inputHex);
179 StringBuffer stringBuffer =new StringBuffer(inputHex);
180// for (int i = 0; i <p-1 ; i++) {
181// stringBuffer.append("00");
182// }
183 ret= Util.hexToByte(stringBuffer.toString());
184 //ret = new byte[input.length + p];
185 /*System.arraycopy(input, 0, ret, 0, input.length);
186 for (int i = 0; i < p; i++) {
187 ret[input.length + i] = (byte) '�';
188 }*/
189 } else {
190 /*int p = input[input.length - 1];
191 ret = new byte[input.length - p];
192 System.arraycopy(input, 0, ret, 0, input.length - p);*/
193
194 String inputHex =Util.byteToHex(input);
195 System.out.println("SM4 " + inputHex);
196 int i = inputHex.lastIndexOf("80");
197 if (i == -1)
198 i = inputHex.lastIndexOf("0b"); // 新增
199 if (i == -1)
200 i = inputHex.lastIndexOf("0a"); // 新增
201 if (i == -1)
202 i = inputHex.lastIndexOf("0c"); // 新增
203 if ( i == -1)
204 i = inputHex.length();
205
206 String substring = inputHex.substring(0, i);
207 ret= Util.hexToByte(substring);
208 System.out.println("208 "+Arrays.toString(ret));
209 }
210 return ret;
211 }
212
213 public void sm4_setkey_enc(SM4_Context ctx, byte[] key) throws Exception {
214 if (ctx == null) {

Callers 2

sm4_crypt_ecbMethod · 0.95
sm4_crypt_cbcMethod · 0.95

Calls 2

byteToHexMethod · 0.95
hexToByteMethod · 0.95

Tested by

no test coverage detected