public static string SM4EncryptECB(string input, string key) { input = ConvertTool.RemoveSpace(input); key = ConvertTool.RemoveSpace(key); if (key.Length != 32) { throw new Exception("Invalid Key, Not 16 bytes"); } if (input.Length % 32 != 0 || input.Length == 0) { throw new Exception("Invalid Data, Not 16*n bytes"); } byte[] output = SM4.Encrypt_ECB(ConvertTool.String2Bytes(input), ConvertTool.String2Bytes(key)); return(ConvertTool.Bytes2String(output)); }
public static string SM4DecryptCBC(string input, string iv, string key) { input = ConvertTool.RemoveSpace(input); key = ConvertTool.RemoveSpace(key); iv = ConvertTool.RemoveSpace(iv); if (key.Length != 32) { throw new Exception("Invalid Key, Not 16 bytes"); } if (input.Length % 32 != 0 || input.Length == 0) { throw new Exception("Invalid Cipher, Not 16*n bytes"); } if (iv.Length != 32) { throw new Exception("Invalid IV, Not 16 bytes"); } byte[] output = SM4.Decrypt_CBC(ConvertTool.String2Bytes(input), ConvertTool.String2Bytes(key), ConvertTool.String2Bytes(iv)); return(ConvertTool.Bytes2String(output)); }