小编ato*_*tom的帖子

调试AES-CMAC,生成错误的答案

我使用以下代码和类从AES_CMAC生成多样化密钥.每次给定输入时,doFinal方法返回不同的键,而masterKey是常量.

 public byte[] calculateDiverseKey(byte [] input) throws InvalidKeyException, NoSuchAlgorithmException {
    AesCmac mac = null;
    mac = new AesCmac();
    SecretKey key = new SecretKeySpec(masterKey, "AES");
    mac.init(key);  //set master key
    mac.updateBlock(input); //given input
    for (byte b: input) System.out.print(" "+b);
    return mac.doFinal();
    }
Run Code Online (Sandbox Code Playgroud)

AesCmac.java类

//package fi.aalto.spothip.crypto;

import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;






import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;

public class AesCmac {
    private static final byte CONSTANT = (byte) 0x87;
    private static final int BLOCK_SIZE = 16;

    private int macLength;
    private Cipher aesCipher;

    private byte[] …
Run Code Online (Sandbox Code Playgroud)

java encryption debugging cryptography aes

6
推荐指数
1
解决办法
2682
查看次数

如何将Chrome扩展ID动态发送到网页以进行消息传递

我通过内容脚本在网页中注入脚本.在脚本中我使用chrome.runtime.sendMessage成功地向后台脚本发送消息.但是我有extensionId硬编码.如何在网页中动态注入扩展ID以将消息发送到后台脚本?

chrome.runtime.sendMessage(extensionIdHardCoded, {
      msg: data
    },
    function(response) {});
Run Code Online (Sandbox Code Playgroud)

javascript google-chrome google-chrome-extension

2
推荐指数
1
解决办法
1387
查看次数