- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
Cipher.getInstance("AES/CBC/PKCS5PADDING") 我使用 Sun JCE 供应商:
public static void main(String[] args) throws UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, ShortBufferException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException
{
System.out.println("=======================AES/CBC/PKCS5Padding=====================");
// key
byte[] key = "0123456789abcdef".getBytes("UTF-8");
dump("key", key);
// iv
byte[] iv = "fedcba9876543210".getBytes("UTF-8");
dump("iv", iv);
byte[] indata = "bsmith is a good guy.".getBytes("UTF-8");
dump("indata", indata);
AES aes = new AES();
aes.init(key, iv);
byte[] outdata = aes.encrypt(indata);
dump("outdata", outdata);
byte[] indata1 = aes.decrypt(outdata);
dump("indata1", indata1);
}
private Cipher enc;
private Cipher dec;
private SecretKeySpec keySpec;
private IvParameterSpec ivSpec;
public AES()
{
}
/**
* init the AES key.
* the key must be 128, 192, or 256 bits.
* @param key the AES key.
* @param keyoff the AES key offset.
* @param keylen the AES key length, the key length must be 16 bytes because SunJCE only support 16 bytes key.
* @param iv the IV for CBC, the length of iv must be 16 bytes.
* @param ivoff the iv offset.
*/
public void init(byte[] key, int keyoff, int keylen, byte[] iv, int ivoff)
{
keySpec = new SecretKeySpec(key, keyoff, keylen, "AES");
ivSpec = new IvParameterSpec(iv, ivoff, 16);
}
/**
* init the AES key.
* the key must be 16 bytes, because SunJCE only support 16 bytes key..
* @param key the AES key.
* @param iv the iv for CBC, iv must be 16 bytes length.
*/
public void init(byte[] key, byte[] iv)
{
keySpec = new SecretKeySpec(key, "AES");
ivSpec = new IvParameterSpec(iv);
}
/**
* get the maximal cipher data length after encrypted.
* @param len the plain data length.
* @return the cipher data length.
*/
public int getCipherLen(int len)
{
// for PKCS#1 v1.5 padding
// max padding BLOCK_SIZE=16.
int pad = len%16;
if (0 == pad)
{
return len + 16;
}
return len - pad + 16;
}
/**
* encrypt the input data to output data.
* the input data length must be the times of 16 bytes.
* and the output data length is equals to the input data.
* @param indata the input data.
* @param inoff the input data offset.
* @param inlen the input data length.
* @param outdata the output data.
* @param outoff the output data offset.
*/
public void encrypt(byte[] indata, int inoff, int inlen, byte[] outdata, int outoff) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, ShortBufferException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException
{
initEncryptor();
enc.doFinal(indata, inoff, inlen, outdata, outoff);
}
/**
* encrypt the input data to output data.
* @param indata the input data.
* @param inoff the input data offset.
* @param inlen the input data length.
* @return the output encrypted data.
*/
public byte[] encrypt(byte[] indata, int inoff, int inlen) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, ShortBufferException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException
{
initEncryptor();
return enc.doFinal(indata, inoff, inlen);
}
/**
* encrypt the input data to output data.
* @param indata the input data.
* @return the output data.
* @throws NoSuchAlgorithmException
* @throws NoSuchPaddingException
* @throws InvalidKeyException
* @throws InvalidAlgorithmParameterException
* @throws IllegalBlockSizeException
* @throws BadPaddingException
*/
public byte[] encrypt(byte[] indata) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException
{
initEncryptor();
return enc.doFinal(indata);
}
/**
* the maximal plain data length after decrypted.
* @param len the cipher data length that will be decrypted.
* @return the maximal plain data length.
*/
public int getPlainLen(int len)
{
// for PKCS#1 v1.5 padding
// len always be times of BLOCK_SIZE=16.
return len;
}
/**
* decrypt the input data to output data.
* @param indata the input data.
* @param inoff the input data offset.
* @param inlen the input data length.
* @param outdata the output data.
* @param outoff the output data offset.
*/
public void decrypt(byte[] indata, int inoff, int inlen, byte[] outdata, int outoff) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, ShortBufferException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException
{
initDecryptor();
dec.doFinal(indata, inoff, inlen, outdata, outoff);
}
/**
* decrypt the input data to output data.
* @param indata the input data.
* @param inoff the input data offset.
* @param inlen the input data length.
* @return the output decrypted data.
*/
public byte[] decrypt(byte[] indata, int inoff, int inlen) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, ShortBufferException, InvalidAlgorithmParameterException
{
initDecryptor();
return dec.doFinal(indata, inoff, inlen);
}
/**
* decrypt the input data to output data.
* @param indata the input cipher data.
* @return the output plain data.
* @throws NoSuchAlgorithmException
* @throws NoSuchPaddingException
* @throws InvalidKeyException
* @throws InvalidAlgorithmParameterException
* @throws IllegalBlockSizeException
* @throws BadPaddingException
*/
public byte[] decrypt(byte[] indata) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException
{
initDecryptor();
return dec.doFinal(indata);
}
private void initEncryptor() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException
{
if (null == enc)
{
enc = Cipher.getInstance("AES/CBC/PKCS5Padding");
enc.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);
}
}
private void initDecryptor() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException
{
if (null == dec)
{
dec = Cipher.getInstance("AES/CBC/PKCS5Padding");
dec.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
}
}
对应什么是C/C++?我发现crypto++ 刚刚好,其他的都没有,但是里面的算法太多了,我只要有AES就行了。那个太复杂了,我不会,我是新手,你熟悉这个算法吗,我想移植一下进入Android,打包成这样。
最佳答案
首先,PKCS#5 填充更广为人知的是 PKCS#7 填充。 PKCS#5 填充实际上用于 8 字节 block 密码,而 PKCS#7 填充用于 16 字节 block 密码。否则它们是相同的。
加密库只要提供AES和CBC就可以了。这或多或少是给定的,因为 CBC 是更常见的模式之一。正确填充模式的可用性可能有所不同,尽管大多数 C++ 库都支持 PKCS#5 填充,因为它是事实上的标准。
由于有可用的 (NIST) 测试 vector ,并且字节顺序已知,因此任何支持算法、模式和填充模式组合的库都应该是可互操作的。
关于c++ - JAVA(AES/CBC/PKCS5PADDING)对应的C/C++是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14008879/
String 有 PadLeft 和 PadRight。我需要左右填充(居中对齐)。是否有执行此操作的标准化方法,或者更好的是,是否有实现相同目标的内置方法? 最佳答案 据我所知没有。如果您发现自己经
我刚开始学习 CSS,所以我的问题很基础。如图,如果设置padding:10px;的,但在结果中,似乎只有顶部和左侧工作,为什么会这样,我的意思是如果使用工作流程,它应该是最后两个底部和左侧工作吗?
我正在尝试重新创建类似于 this 的内容.我注意到输入字段不能在 内因为那样他们会得到难看的填充物。另一方面,按钮需要此填充,否则它会粘在没有任何填充的一侧。 以下代码不起作用,因为它将按钮放置在
我正在尝试将以下 Keras 模型代码转换为 pytorch,但在处理 padding='same' 时遇到问题。 model = Sequential() model.add(Con
与主题中的问题相同,有时是否可以将 pad 从例如 decodebin 元素链接到其他兼容元素的 pad? 我正在尝试做这样的事情: GstElement *decodebin = gst_eleme
尝试使用相同的数据集依次评估一堆 transformers 模型,以检查哪个模型表现更好。 模型列表是这个: MODELS = [ ('xlm-mlm-enfr-1024' ,"XLM
尝试使用相同的数据集依次评估一堆 transformers 模型,以检查哪个模型表现更好。 模型列表是这个: MODELS = [ ('xlm-mlm-enfr-1024' ,"XLM
根据 http://www.maxdesign.com.au/articles/inline/ ,名为“内联元素和填充”的部分说 While padding can be applied to all
在 的左侧和右侧有 3px 的填充标记导致顶部和底部填充。请参阅此处的示例...(但是对于这个 jsfiddle,我只复制了底部的填充,而不是顶部的填充)。 #xyz { padding-r
我有一个滚动时间线 ( demo ),我遇到了 padding-left 在滚动之前隐藏时间线左侧的时间线分支图像的问题, 但 padding-right 无法隐藏右侧的分支图像。 我尝试使用的方法是
我不想用这个来骚扰你,但我在互联网上的任何地方都找不到对“位填充”到底是什么的详细解释,也没有找到与位填充相关的线程的任何答案在 StackOverflow 上。 我还在 ISO 9899-1990
在检查一些代码时,我发现了这个新声明:-webkit-padding-start 但我无法理解与现有的 padding-left 有什么区别属性(property)。我已经阅读了 Mozilla De
这是我的CSS: body { margin: 0px; background-color: white; } #navbar { background-color: red; margin: 0 a
所以我试图获得一些带有填充的文本修饰符,在我导入 androidx.compose.foundation.layout.padding 之前一切都很好以及 Modifier.padding(10.dp
我正在尝试使用 Python 的 base64.b64decode(str) 方法对字符串进行 Base64 解码(转换为字节): 46oWrWpy2gTEGwNnN6Ayy 并且我确保它有 4 个
两台不同的计算机(相同的 python 版本)为 time.ctime() 返回不同的格式。一个返回 "Sun May 6 14:04:28 2018" 月份前有2个空格;其他返回 "Sun May
代码中没有设置右边距或右边距的地方,当在 Chrome 的开发者工具中查看表单元素时,它在样式列表中同时显示“padding: 0”和“margin: 0”,但是 确实将鼠标悬停在表单元素上时显示边距
有没有办法在 Flexbox 中将 padding-left 和 padding-right 设置为元素宽度的 10%。我尝试使用 padding: 0 10%;,但它不是元素宽度的 10%。 .fl
image codepen 你好,我需要 CSS 样式方面的帮助。 我正在尝试有一个响应式主菜单,但无法想出一种方法来保持文本在元素框中水平居中,一旦这些由于视口(viewport)宽度较低而开始缩小
androidx.compose.material3.Scaffold 填充错误地添加了导航栏填充,即使在打开软键盘时添加了 IME 填充,导致导航栏填充量加倍(请参见下面的屏幕截图,分隔线应该接触到
我是一名优秀的程序员,十分优秀!