Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python jpype从java类的实例获取值_Java_Python_Jpype - Fatal编程技术网

python jpype从java类的实例获取值

python jpype从java类的实例获取值,java,python,jpype,Java,Python,Jpype,我有一个类似的代码 message = "abc".encode() messageDigest = java.security.MessageDigest.getInstance("SHA-256") messageDigest.update(message) hashdata = messageDigest.digest() 在这里,当我打印hashdata时,我得到 但我需要它的价值。如何获取其值?试试这个 for (int i = 0; i < hash.length; i++)

我有一个类似的代码

message = "abc".encode()
messageDigest = java.security.MessageDigest.getInstance("SHA-256")
messageDigest.update(message)
hashdata = messageDigest.digest()
在这里,当我打印
hashdata
时,我得到

但我需要它的价值。如何获取其值?

试试这个

for (int i = 0; i < hash.length; i++) {
    if ((0xff & hash[i]) < 0x10) {
        hexString.append("0"
                + Integer.toHexString((0xFF & hash[i])));
    } else {
        hexString.append(Integer.toHexString(0xFF & hash[i]));
    }
}
for(int i=0;i
目前,我们不支持Java字节数组的
\uuuuu字节
运算符,但它很容易通过自定义程序添加

import jpype
from jpype import java

# Add the customizer before starting the JVM
@jpype.JImplementationFor('byte[]')
class ByteConverter(object):
    def __bytes__(self):
        return bytes(self[:])

# Now start the JVM
jpype.startJVM(convertStrings=False)

# Perform Java operations
message = "abc".encode()
messageDigest = java.security.MessageDigest.getInstance("SHA-256")
messageDigest.update(message)
hashdata = messageDigest.digest()

# We got back a Java byte[] and we would like a Python bytes
print(bytes(hashdata))

像这样使用<代码>字符串hashdata=新字符串(messageDigest.digest())