Skip to content

HmacSHA256 using a RSA key should fail #2220

@lhuynh-cs

Description

@lhuynh-cs

The below code should fail instead of computing the seal :

		byte[] input = "The quick brown fox jumps over the lazy dog".getBytes("UTF-8");
		
		Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

		KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "BC");
		kpg.initialize(2048);

		Mac mac = Mac.getInstance("HmacSHA256", "BC");

		KeyPair kp = kpg.generateKeyPair();
        mac.init(kp.getPrivate());

        byte[] seal = mac.doFinal(input);

Indeed, according to JCA Reference Guide:

HMAC can be used with any cryptographic hash function, e.g., SHA-256, in combination with a secret shared key

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions