相关疑难解决方法(0)

如何在swift中将数据转换为十六进制字符串

我想要在Swift中使用数据值的十六进制表示.

最终我想要像这样使用它:

let data = Data(base64Encoded: "aGVsbG8gd29ybGQ=")!
print(data.hexString)
Run Code Online (Sandbox Code Playgroud)

swift swift3

62
推荐指数
6
解决办法
4万
查看次数

在swift中实现HMAC和SHA1加密

我对Swift相对较新,而且我使用HMAC和SHA1进行加密.我找到了以下答案/sf/answers/1708806571/但我无法弄清楚如何正确实现这一点.任何帮助都会很棒.

ios swift xcode6

16
推荐指数
5
解决办法
2万
查看次数

在Java中使用带有密钥的ripemd160模拟php函数hash_hmac中的字符串

我正在尝试使用Java来散列Java中的String ripemd160来模拟以下php的输出:

$string = 'string';
$key = 'test';

hash_hmac('ripemd160', $string, $key);

// outputs: 37241f2513c60ae4d9b3b8d0d30517445f451fa5
Run Code Online (Sandbox Code Playgroud)


尝试1

最初我尝试使用以下方法模拟它...但是我不相信它可以ripemd160用作getInstance`算法吗?

或许它是,我只是没有在本地启用它?

public String signRequest(String uri, String secret) {
    try {

        byte[] keyBytes = secret.getBytes();           
        SecretKeySpec signingKey = new SecretKeySpec(keyBytes, "HmacSHA1");

        Mac mac = Mac.getInstance("ripemd160");
        mac.init(signingKey);

        // Compute the hmac on input data bytes
        byte[] rawHmac = mac.doFinal(uri.getBytes());

        // Convert raw bytes to Hex
        byte[] hexBytes = new Hex().encode(rawHmac);

        //  Covert array of Hex bytes to a String
        return new String(hexBytes, "UTF-8"); …
Run Code Online (Sandbox Code Playgroud)

java hash

7
推荐指数
1
解决办法
460
查看次数

标签 统计

swift ×2

hash ×1

ios ×1

java ×1

swift3 ×1

xcode6 ×1