本文整理匯總了Java中javax.crypto.Mac.doFinal方法的典型用法代碼示例。如果您正苦於以下問題:Java Mac.doFinal方法的具體用法?Java Mac.doFinal怎麽用?Java Mac.doFinal使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.crypto.Mac的用法示例。

在下文中一共展示了Mac.doFinal方法的19個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: if

​點讚 3

import javax.crypto.Mac; //導入方法依賴的package包/類

private byte[] b0449щ0449щ04490449(String str, byte[] bArr) throws Exception {

try {

String str2 = "HmacSHA256";

if (((bХ0425ХХХХ + bХХ0425ХХХ) * bХ0425ХХХХ) % bХ042504250425ХХ != b04250425ХХХХ) {

bХ0425ХХХХ = 57;

b04250425ХХХХ = bХ04250425ХХХ();

}

try {

Mac instance = Mac.getInstance(str2);

instance.init(new SecretKeySpec(bArr, str2));

return instance.doFinal(str.getBytes(UrlUtils.UTF8));

} catch (Exception e) {

throw e;

}

} catch (Exception e2) {

throw e2;

}

}

開發者ID:JackChan1999,項目名稱:letv,代碼行數:19,

示例2: doSign

​點讚 3

import javax.crypto.Mac; //導入方法依賴的package包/類

private static String doSign(String baseString) {

String apiSecret = Constants.FanFou.CONSUMER_SECRET;

String tokenSecret = Constants.FanFou.OAUTH_TOKENSECRET;

String keyString = OAuthEncoder.encode(apiSecret) + '&';

if (tokenSecret != null) {

keyString += OAuthEncoder.encode(tokenSecret);

}

try {

SecretKeySpec key = new SecretKeySpec(keyString.getBytes(CHARSET), HMAC_SHA1);

Mac mac = Mac.getInstance(HMAC_SHA1);

mac.init(key);

byte[] bytes = mac.doFinal(baseString.getBytes(CHARSET));

return bytesToBase64String(bytes).replace(CARRIAGE_RETURN, EMPTY_STRING);

} catch (Exception e) {

e.printStackTrace();

Logger.e("doSign error:" + e.getMessage());

throw new RuntimeException(e);

}

}

開發者ID:betroy,項目名稱:xifan,代碼行數:21,

示例3: calculateRFC2104HMAC

​點讚 3

import javax.crypto.Mac; //導入方法依賴的package包/類

/**

* Computes RFC 2104-compliant HMAC signature.

* * @param data

* The data to be signed.

* @param key

* The signing key.

* @return

* The Base64-encoded RFC 2104-compliant HMAC signature.

* @throws

* SignatureException when signature generation fails

*/

private static String calculateRFC2104HMAC(String data, String key)

throws SignatureException

{

String result;

try {

// get an hmac_sha1 key from the raw key bytes

SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), HMAC_SHA1_ALGORITHM);

// get an hmac_sha1 Mac instance and initialize with the signing key

Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);

mac.init(signingKey);

// compute the hmac on input data bytes

byte[] rawHmac = mac.doFinal(data.getBytes());

// base64-encode the hmac

result = EncodeBase64(rawHmac);

} catch (Exception e) {

throw new SignatureException("Failed to generate HMAC : " + e.getMessage());

}

return result;

}

開發者ID:aysenurbilgin,項目名稱:cww_framework,代碼行數:36,

示例4: createSign

​點讚 3

import javax.crypto.Mac; //導入方法依賴的package包/類

private String createSign(String message) throws BitbankException {

try {

String algo = "HmacSHA256";

String secret = this.apiSecret;

SecretKeySpec sk = new SecretKeySpec(secret.getBytes(), algo);

Mac mac = Mac.getInstance(algo);

mac.init(sk);

byte[] macBytes = mac.doFinal(message.getBytes());

StringBuilder sb = new StringBuilder(2 * macBytes.length);

for(byte b: macBytes) {

sb.append(String.format("%02x", b&0xff) );

}

return sb.toString();

} catch (Exception e) {

throw new BitbankException(e.getMessage());

}

}

開發者ID:bitbankinc,項目名稱:java-bitbankcc,代碼行數:20,

示例5: doTest

​點讚 3

import javax.crypto.Mac; //導入方法依賴的package包/類

private void doTest(String algo, Provider provider)

throws NoSuchAlgorithmException, NoSuchProviderException,

InvalidKeyException {

System.out.println("Test " + algo);

Mac mac;

try {

mac = Mac.getInstance(algo, provider);

} catch (NoSuchAlgorithmException nsae) {

if ("SunPKCS11-Solaris".equals(provider.getName())) {

// depending on Solaris configuration,

// it can support HMAC or not with Mac

System.out.println("Expected NoSuchAlgorithmException thrown: "

+ nsae);

return;

}

throw nsae;

}

byte[] plain = new byte[MESSAGE_SIZE];

for (int i = 0; i < MESSAGE_SIZE; i++) {

plain[i] = (byte) (i % 256);

}

byte[] tail = new byte[plain.length - OFFSET];

System.arraycopy(plain, OFFSET, tail, 0, tail.length);

SecureRandom srdm = new SecureRandom();

byte[] keyVal = new byte[KEY_SIZE];

srdm.nextBytes(keyVal);

SecretKeySpec keySpec = new SecretKeySpec(keyVal, "HMAC");

mac.init(keySpec);

byte[] result1 = mac.doFinal(plain);

mac.reset();

mac.update(plain[0]);

mac.update(plain, 1, OFFSET - 1);

byte[] result2 = mac.doFinal(tail);

if (!java.util.Arrays.equals(result1, result2)) {

throw new RuntimeException("result1 and result2 are not the same");

}

}

開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:44,

示例6: encodeHmacSHA384

​點讚 2

import javax.crypto.Mac; //導入方法依賴的package包/類

/**

* HmacSHA384加密

*

* @param data 待加密數據

* @param key 密鑰

* @return byte[] 消息摘要

* @throws Exception

*/

public static byte[] encodeHmacSHA384(byte[] data, byte[] key) throws Exception {

// 還原密鑰

SecretKey secretKey = new SecretKeySpec(key, "HmacSHA384");

// 實例化Mac

Mac mac = Mac.getInstance(secretKey.getAlgorithm());

// 初始化Mac

mac.init(secretKey);

// 執行消息摘要

return mac.doFinal(data);

}

開發者ID:guokezheng,項目名稱:automat,代碼行數:19,

示例7: encodeHmacMD2

​點讚 2

import javax.crypto.Mac; //導入方法依賴的package包/類

/**

* HmacMD2消息摘要

*

* @param data 待做消息摘要處理的數據

* @param key 密鑰

* @throws Exception

*/

public static byte[] encodeHmacMD2(byte[] data, byte[] key) throws Exception {

// 還原密鑰

SecretKey secretKey = new SecretKeySpec(key, "HmacMD2");

// 實例化Mac

Mac mac = Mac.getInstance(secretKey.getAlgorithm());

// 初始化Mac

mac.init(secretKey);

// 執行消息摘要

return mac.doFinal(data);

}

開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:18,

示例8: execute

​點讚 2

import javax.crypto.Mac; //導入方法依賴的package包/類

@Override

public void execute(IngestDocument ingestDocument) throws Exception {

List> list = null;

try {

String in = ingestDocument.getFieldValue(field, String.class);

list = new ArrayList<>(Arrays.asList(in));

} catch (IllegalArgumentException e) {

list = ingestDocument.getFieldValue(field, ArrayList.class, true);

if (list == null)

throw new IllegalArgumentException("field [" + field + "] is null, cannot do fingerprint.");

}

Mac mac = Mac.getInstance(method);

SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(Charset.defaultCharset()), method);

mac.init(signingKey);

ArrayList outcontent = new ArrayList<>(list.size());

for (Object o : list) {

String s = o.toString();

byte[] b = mac.doFinal(s.getBytes(Charset.defaultCharset()));

String hash = new BigInteger(1, b).toString(16);

outcontent.add(hash);

}

if (outcontent.size() == 1)

ingestDocument.setFieldValue(target_field, outcontent.get(0));

else

ingestDocument.setFieldValue(target_field, outcontent);

}

開發者ID:sektorcap,項目名稱:ingest-fingerprint,代碼行數:28,

示例9: verifySignature

​點讚 2

import javax.crypto.Mac; //導入方法依賴的package包/類

public static boolean verifySignature(String payload, String signature, String secret) {

boolean isValid;

try {

Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);

SecretKeySpec signingKey = new SecretKeySpec(secret.getBytes(), HMAC_SHA1_ALGORITHM);

mac.init(signingKey);

byte[] rawHmac = mac.doFinal(payload.getBytes());

String expected = signature.substring(5);

String actual = new String(encode(rawHmac));

isValid = expected.equals(actual);

} catch (NoSuchAlgorithmException | InvalidKeyException | IllegalStateException ex) {

throw new RuntimeException(ex.getLocalizedMessage());

}

return isValid;

}

開發者ID:codeclou,項目名稱:jenkins-github-webhook-build-trigger-plugin,代碼行數:16,

示例10: getHmacEncodingFor

​點讚 2

import javax.crypto.Mac; //導入方法依賴的package包/類

private String getHmacEncodingFor(

String signature

) throws

NoSuchAlgorithmException,

InvalidKeyException, UnsupportedEncodingException

{

Mac hasher = Mac.getInstance(HMAC_SHA1_ALGORITHM);

hasher.init(new SecretKeySpec(Configuration.hmacAuthPassword.getBytes(), HMAC_SHA1_ALGORITHM));

byte[] hash = hasher.doFinal(signature.getBytes());

String base64Encoded = Base64.getEncoder().encodeToString(hash);

return base64Encoded;

}

開發者ID:messagemedia,項目名稱:messages-java-sdk,代碼行數:16,

示例11: doSign

​點讚 2

import javax.crypto.Mac; //導入方法依賴的package包/類

private String doSign(String toSign, String keyString) throws Exception

{

// Logger.getLogger("is it signing","----------------------"+toSign);

// Logger.getLogger("is 22222222",keyString+"");

SecretKeySpec key = new SecretKeySpec((keyString).getBytes(UTF8), HMAC_SHA1);

Mac mac = Mac.getInstance(HMAC_SHA1);

mac.init(key);

byte[] bytes = mac.doFinal(toSign.getBytes(UTF8));

return bytesToBase64String(bytes).replace(CARRIAGE_RETURN, EMPTY_STRING);

}

開發者ID:farhanhedr,項目名稱:woocommerce-oauth1.0-java,代碼行數:13,

示例12: hmacSha1

​點讚 2

import javax.crypto.Mac; //導入方法依賴的package包/類

/**

*

* @param data data to hash

* @param key key used

* @return created hmacsha1

*/

public static byte[] hmacSha1(byte[] data, byte[] key) {

try {

// Get an hmac_sha1 key from the raw key bytes;

SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1");

// Get an hmac_sha1 Mac instance and initialize with the signing key

Mac mac = Mac.getInstance("HmacSHA1");

mac.init(signingKey);

// Compute the hmac on input data bytes

return mac.doFinal(data);

} catch (Exception e) {

throw new RuntimeException(e);

}

}

開發者ID:IIlllII,項目名稱:bitbreeds-webrtc,代碼行數:20,

示例13: encodeHmacSHA384

​點讚 2

import javax.crypto.Mac; //導入方法依賴的package包/類

/**

* HmacSHA384加密

*

* @param data 待加密數據

* @param key 密鑰

* @throws Exception

*/

public static byte[] encodeHmacSHA384(byte[] data, byte[] key) throws Exception {

// 還原密鑰

SecretKey secretKey = new SecretKeySpec(key, "HmacSHA384");

// 實例化Mac

Mac mac = Mac.getInstance(secretKey.getAlgorithm());

// 初始化Mac

mac.init(secretKey);

// 執行消息摘要

return mac.doFinal(data);

}

開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:18,

示例14: createPassword

​點讚 2

import javax.crypto.Mac; //導入方法依賴的package包/類

/**

* Compute HMAC of the identifier using the secret key and return the

* output as password

* @param identifier the bytes of the identifier

* @param key the secret key

* @return the bytes of the generated password

*/

protected static byte[] createPassword(byte[] identifier,

SecretKey key) {

Mac mac = threadLocalMac.get();

try {

mac.init(key);

} catch (InvalidKeyException ike) {

throw new IllegalArgumentException("Invalid key to HMAC computation",

ike);

}

return mac.doFinal(identifier);

}

開發者ID:naver,項目名稱:hadoop,代碼行數:19,

示例15: doTest

​點讚 2

import javax.crypto.Mac; //導入方法依賴的package包/類

/**

* Uses a random generator to initialize a message, instantiate a Mac object

* according to the given PBMAC1 algorithm, initialize the object with a

* SecretKey derived using PBKDF2 algorithm (see PKCS #5 v21, chapter 7.1),

* feed the message into the Mac object all at once and get the output MAC

* as result1. Reset the Mac object, chop the message into three pieces,

* feed into the Mac object sequentially, and get the output MAC as result2.

* Finally, compare result1 and result2 and see if they are the same.

*

* @param theMacAlgo PBMAC algorithm to test

* @param thePBKDF2Algo PBKDF2 algorithm to test

* @return true - the test is passed; false - otherwise.

* @throws NoSuchAlgorithmException

* @throws InvalidKeyException

* @throws InvalidKeySpecException

*/

protected boolean doTest(String theMacAlgo, String thePBKDF2Algo)

throws NoSuchAlgorithmException, InvalidKeyException,

InvalidKeySpecException {

int OFFSET = 5;

// Some message for which a MAC result will be calculated

byte[] plain = new byte[25];

new SecureRandom().nextBytes(plain);

// Form tail - is one of the three pieces

byte[] tail = new byte[plain.length - OFFSET];

System.arraycopy(plain, OFFSET, tail, 0, tail.length);

// Obtain a SecretKey using PBKDF2

SecretKey key = getSecretKey(thePBKDF2Algo);

// Instantiate Mac object and init it with a SecretKey and calc result1

Mac theMac = Mac.getInstance(theMacAlgo);

theMac.init(key);

byte[] result1 = theMac.doFinal(plain);

if (!isMacLengthExpected(theMacAlgo, result1.length)) {

return false;

}

// Reset Mac and calculate result2

theMac.reset();

theMac.update(plain[0]);

theMac.update(plain, 1, OFFSET - 1);

byte[] result2 = theMac.doFinal(tail);

// Return result

if (!java.util.Arrays.equals(result1, result2)) {

System.out.println("result1 and result2 are not the same:");

System.out.println("result1: " + dumpByteArray(result1));

System.out.println("result2: " + dumpByteArray(result2));

return false;

} else {

System.out.println("Resulted MAC with update and doFinal is same");

}

return true;

}

開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:60,

示例16: decrypt

​點讚 2

import javax.crypto.Mac; //導入方法依賴的package包/類

public static byte[] decrypt(byte[] secure, ExternalContext ctx)

{

if (ctx == null)

{

throw new NullPointerException("ExternalContext ctx");

}

testConfiguration(ctx);

SecretKey secretKey = (SecretKey) getSecret(ctx);

String algorithm = findAlgorithm(ctx);

String algorithmParams = findAlgorithmParams(ctx);

byte[] iv = findInitializationVector(ctx);

SecretKey macSecretKey = (SecretKey) getMacSecret(ctx);

String macAlgorithm = findMacAlgorithm(ctx);

try

{

// keep local to avoid threading issue

Mac mac = Mac.getInstance(macAlgorithm);

mac.init(macSecretKey);

Cipher cipher = Cipher.getInstance(algorithm + "/"

+ algorithmParams);

if (iv != null)

{

IvParameterSpec ivSpec = new IvParameterSpec(iv);

cipher.init(Cipher.DECRYPT_MODE, secretKey, ivSpec);

}

else

{

cipher.init(Cipher.DECRYPT_MODE, secretKey);

}

if (log.isLoggable(Level.FINE))

{

log.fine("decrypting w/ " + algorithm + "/" + algorithmParams);

}

//EtM Composition Approach

int macLenght = mac.getMacLength();

mac.update(secure, 0, secure.length-macLenght);

byte[] signedDigestHash = mac.doFinal();

boolean isMacEqual = true;

for (int i = 0; i < signedDigestHash.length; i++)

{

if (signedDigestHash[i] != secure[secure.length-macLenght+i])

{

isMacEqual = false;

// MYFACES-2934 Must compare *ALL* bytes of the hash,

// otherwise a side-channel timing attack is theorically possible

// but with a very very low probability, because the

// comparison time is too small to be measured compared to

// the overall request time and in real life applications,

// there are too many uncertainties involved.

//break;

}

}

if (!isMacEqual)

{

throw new ViewExpiredException();

}

return cipher.doFinal(secure, 0, secure.length-macLenght);

}

catch (Exception e)

{

throw new FacesException(e);

}

}

開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:71,

示例17: encrypt

​點讚 1

import javax.crypto.Mac; //導入方法依賴的package包/類

/**

* HMAC加密

*

* @param plain 明文

* @param key key

* @param algorithm 算法,可為空。默認為:Algorithm.Hmac_MD5

* @return

* @throws Exception

*/

public static byte[] encrypt(byte[] plain, String key, Algorithm algorithm) throws Exception {

if (algorithm == null) algorithm = Algorithm.Hmac_MD5;

SecretKey secretKey = new SecretKeySpec(BASE64.decode(key), algorithm.getType());

Mac mac = Mac.getInstance(secretKey.getAlgorithm());

mac.init(secretKey);

return mac.doFinal(plain);

}

開發者ID:lzmlsfe,項目名稱:19porn,代碼行數:18,

示例18: hmacSha

​點讚 1

import javax.crypto.Mac; //導入方法依賴的package包/類

/**

* This method uses the JCE to provide the crypto algorithm. HMAC computes a

* Hashed Message Authentication Code with the crypto hash algorithm as a

* parameter.

*

* @param crypto

* : the crypto algorithm (HmacSHA1, HmacSHA256, HmacSHA512)

* @param keyBytes

* : the bytes to use for the HMAC key

* @param text

* : the message or text to be authenticated

*/

private static byte[] hmacSha(String crypto, byte[] keyBytes, byte[] text) {

try {

Mac hmac;

hmac = Mac.getInstance(crypto);

SecretKeySpec macKey = new SecretKeySpec(keyBytes, RAW);

hmac.init(macKey);

return hmac.doFinal(text);

} catch (GeneralSecurityException gse) {

throw new UndeclaredThrowableException(gse);

}

}

開發者ID:daishicheng,項目名稱:outcomes,代碼行數:24,

示例19: encrypt

​點讚 1

import javax.crypto.Mac; //導入方法依賴的package包/類

/**

* HMAC加密

*

* @param plain 明文

* @param key key

* @param type 算法,可為空。默認為:CipherType.Hmac_MD5

* @return

* @throws Exception

*/

public static byte[] encrypt(byte[] plain, String key, CipherType type) throws Exception {

if (type == null) type = CipherType.Hmac_MD5;

SecretKey secretKey = new SecretKeySpec(BASE64.decode(key), type.getType());

Mac mac = Mac.getInstance(secretKey.getAlgorithm());

mac.init(secretKey);

return mac.doFinal(plain);

}

開發者ID:jeasinlee,項目名稱:AndroidBasicLibs,代碼行數:17,

注:本文中的javax.crypto.Mac.doFinal方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

java dofinal_Java Mac.doFinal方法代碼示例相关推荐

  1. java servicefactory_Java DirectoryServiceFactory.getDirectoryService方法代碼示例

    本文整理匯總了Java中org.apache.directory.server.core.factory.DirectoryServiceFactory.getDirectoryService方法的典 ...

  2. java getstringarray_Java AnnotationAttributes.getStringArray方法代碼示例

    本文整理匯總了Java中org.springframework.core.annotation.AnnotationAttributes.getStringArray方法的典型用法代碼示例.如果您正苦 ...

  3. java getselecteditem_Java JComboBox.getSelectedItem方法代碼示例

    本文整理匯總了Java中javax.swing.JComboBox.getSelectedItem方法的典型用法代碼示例.如果您正苦於以下問題:Java JComboBox.getSelectedIt ...

  4. java setlocation_Java Point.setLocation方法代碼示例

    本文整理匯總了Java中java.awt.Point.setLocation方法的典型用法代碼示例.如果您正苦於以下問題:Java Point.setLocation方法的具體用法?Java Poin ...

  5. java setpriority_Java TaskEntity.setPriority方法代碼示例

    本文整理匯總了Java中org.activiti.engine.impl.persistence.entity.TaskEntity.setPriority方法的典型用法代碼示例.如果您正苦於以下問題 ...

  6. java importgeopoint_Java GeoPoint.project方法代碼示例

    本文整理匯總了Java中com.nextgis.maplib.datasource.GeoPoint.project方法的典型用法代碼示例.如果您正苦於以下問題:Java GeoPoint.proje ...

  7. java hssffont_Java HSSFFont.setColor方法代碼示例

    本文整理匯總了Java中org.apache.poi.hssf.usermodel.HSSFFont.setColor方法的典型用法代碼示例.如果您正苦於以下問題:Java HSSFFont.setC ...

  8. java disconnect_Java BlockingConnection.disconnect方法代碼示例

    本文整理匯總了Java中org.fusesource.mqtt.client.BlockingConnection.disconnect方法的典型用法代碼示例.如果您正苦於以下問題:Java Bloc ...

  9. java proertyutils_Java IFile.exists方法代碼示例

    本文整理匯總了Java中org.eclipse.core.resources.IFile.exists方法的典型用法代碼示例.如果您正苦於以下問題:Java IFile.exists方法的具體用法?J ...

最新文章

  1. iOS infoplist 权限设置
  2. image控件显示图片_Unity之Image amp; Raw Image
  3. 从LINQ开始之LINQ to Objects(上)
  4. 使用Java程序通过http post访问Application server
  5. 对一组同构对象用单数组表示法实现(算法导论第十章10.3-2)
  6. 再见 Spring Task,这个定时任务框架真香!
  7. apache支持mysql ubuntu_Ubuntu+Apache+PHP+Mysql环境搭建(完整版)
  8. 新松机器人刻蚀机_中国最大机器人产业基地新松智慧园在沈阳启用
  9. MacBooster清理除Mac大文件和旧文件
  10. SPSS基本数据处理(三)
  11. IDM的Google商店插件
  12. 图像标签制作工具之labelImg-windows的安装与使用
  13. QQ查看撤回的语音消息,slk 文件转 mp3
  14. 阿里云MVP精选2018年终盘点:大咖专访+最佳实践,丰富干货等你来!...
  15. 计算图片中矩形间的IOU
  16. 【Centos】sshd 无法启动(解决问题篇,附问题排查思路和解决方法)
  17. 离散数学(二):命题公式的等值演算
  18. Android常见系统问题分析工具
  19. Python第9章 类
  20. Visual C# 的DirectX开发系列一初识DirectX

热门文章

  1. 数位dp入门题 洛谷P2657 [SCOI2009] windy 数
  2. Cartographer分枝定界算法比喻理解
  3. matlab 正则化表达式_Matlab-------regexp正则表达式
  4. 基于ASP.NET+ SQL2008鲜花管理与订购系统【100010391】
  5. 如何配置无线路由为交换机模式
  6. 常用CAD快捷键命令大全
  7. 今天git拉取下来代码后,明天怎么更新下来别的技术传上去的代码呢?
  8. 【详细说明】二代身份证号码的组成结构(含校验码算法与行政区划代码)
  9. 洗衣粉等日化用品将受油价高企影响涨价
  10. 手把手教你编写脚本批量实现k8s镜像部署