Cipher

Cipher的七个主要公有属性

  • 1、ENCRYPT_MODE,整型值1,加密模式,用于Cipher的初始化。
  • 2、DECRYPT_MODE,整型值2,解密模式,用于Cipher的初始化。
  • 3、WRAP_MODE,整型值3,包装密钥模式,用于Cipher的初始化。
  • 4、UNWRAP_MODE,整型值4,解包装密钥模式,用于Cipher的初始化。
  • 5、PUBLIC_KEY,整型值1,解包装密钥模式下指定密钥类型为公钥。
  • 6、PRIVATE_KEY,整型值2,解包装密钥模式下指定密钥类型为私钥。
  • 7、SECRET_KEY,整型值3,解包装密钥模式下指定密钥类型为密钥,主要用于不是非对称加密的密钥(只有一个密钥,不包含私钥和公钥)

初始化TEEC_Operation类型的变量,并根据实际需要借助TEEC_PARAM_TYPES宏来设定TEEC_Operation类型变量中paramTypes成员的值,该值规定传递到OP-TEE中的最多4个变量缓存或者是数据的作用(作为输入还是输出)。并且还要根据paramTypes的值设定对应的params[x]成员的值或者是指向的地址以及缓存的长度

public static void arraycopy(Object src,int srcPos,Object dest,int destPos,int length)
作用:将指定源数组中的数组从指定位置复制到目标数组的指定位置。
参数:

src - 源数组。

srcPos - 源数组中的起始位置。

dest - 目标数组。

destPos - 目的地数据中的起始位置。

length - 要复制的源数组元素的数量

Integer.toHexString  十进制转成十六进制

String toHexString(int i) //以十六进制(基数 16)无符号整数形式返回一个整数参数的字符串表示形式。

也就是将传入的数值十进制转成十六进制

System.out.println("十进制转十六进制:"+Integer.toHexString(120)); 
十进制转十六进制:78

一个十六进制数(Hex),正好为4个二进制位。一个字节(byte)为8个二进制位。因此,一个字节可表示为两个十六进制数字。

    因此,我们可以将一个byte用两个Hex表示,同理,我们也可以将两个Hex转换为一个byte

  • jclass GetObjectClass(jobject obj) 根据一个对象,获取该对象的类

这个方法比较好理解,根据上面我们讲的根据jobject的类型,我们在JNI中写方法的时候如果是非静态的都会传一个jobject的对象。我们可以根据传入的来获取当前对象的类

void SetArrayRegion(JNIEnv *env, ArrayType array,jsize start, jsize len, const Type *buf):上面方法的对应方法,将缓冲区的部分数据设置回Java原始数组中

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The Java Cipher class provides encryption and decryption functionality in Java. It uses a cryptographic algorithm to perform the encryption and decryption operations. Some common symmetric encryption algorithms include AES, DES, and Blowfish. To use the Cipher class, you first need to create a Cipher object by specifying the encryption algorithm, mode of operation, and padding scheme. Once you have created the Cipher object, you can use it to encrypt or decrypt data. Here's an example of how to use the Cipher class to encrypt and decrypt data using the AES algorithm: ```java import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; public class CipherExample { public static void main(String[] args) throws Exception { String plainText = "This is some plain text"; // Generate a secret key for the AES algorithm KeyGenerator keyGen = KeyGenerator.getInstance("AES"); keyGen.init(256); SecretKey secretKey = keyGen.generateKey(); // Create a Cipher object using the AES algorithm Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); // Encrypt the plain text using the secret key cipher.init(Cipher.ENCRYPT_MODE, secretKey); byte[] encryptedText = cipher.doFinal(plainText.getBytes()); // Decrypt the encrypted text using the same secret key cipher.init(Cipher.DECRYPT_MODE, secretKey); byte[] decryptedText = cipher.doFinal(encryptedText); System.out.println("Plain text: " + plainText); System.out.println("Encrypted text: " + new String(encryptedText)); System.out.println("Decrypted text: " + new String(decryptedText)); } } ``` In this example, we first generate a secret key using the AES algorithm with a key size of 256 bits. We then create a Cipher object using the AES algorithm with CBC mode and PKCS5Padding padding scheme. We use this Cipher object to encrypt the plain text by calling the doFinal method with the Cipher.ENCRYPT_MODE parameter. We then decrypt the encrypted text using the same Cipher object by calling the doFinal method with the Cipher.DECRYPT_MODE parameter. Note that you should always use a secure key size and algorithm when encrypting sensitive data. Also, be sure to store the secret key securely and never share it with unauthorized parties.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值