Java AES Salesforce

————————————–[下記開発例-S]—————————————-
Sample code Download
ApexCryptSample
JavaCryptSample

Java Decode Apex Encode String:new String(CryptUtil128.decrypt(Base64.decode(apex encode String));

————————————–[上記開発例-E]—————————————-

Ref Link
——————————————————————————————–
————————————–[上記参照例]—————————————-
package com.ilhwa.crypto;

import java.io.UnsupportedEncodingException;
import java.security.AlgorithmParameters;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidParameterSpecException;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;

public class Crypto {

public static void main(String[] args) {

// 平文のパスワード

String plainText = “sBivNq2p”;

// 32byte(256bit)のキー

byte[] key = “0xnF7TvvRrkUk7FvfdT6mjF83RRoJoYD”.getBytes();

try {
System.out.println(“Plain Text : ” + plainText);
System.out.println(“Plain Text Base64 : ” + Base64.encode(plainText.getBytes()));
System.out.println(“Key Base64 : ” + Base64.encode(key));

AlgorithmParameters ap = AlgorithmParameters.getInstance(ALGORITHM_NAME);

// 16byteの初期化ベクトル

ap.init(new IvParameterSpec(“oG1s7oSD2hTSb4Z6”.getBytes()));

// 暗号化

byte[] encrypted = encrypt(plainText, key, ap);

System.out.println(“Encrypted Text Base64 : ” + Base64.encode(encrypted));

// 復号

byte[] decrypted = decrypt(encrypted, key, ap);

System.out.println(“Decrypted Text : ” + new String(decrypted));

}
catch (Exception e) {
e.printStackTrace();
}
}

public static byte[] encrypt(String plainText, byte[] key, AlgorithmParameters ap)
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException,
InvalidParameterSpecException, InvalidAlgorithmParameterException {

if (plainText == null || plainText.length() == 0 || key == null || key.length == 0) {

return new byte[0];
}

SecretKeySpec sks = new SecretKeySpec(key, ALGORITHM_NAME);

Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, sks, ap);

// ここで出力される iv を Salesforce 側で指定する

byte[] iv = cipher.getIV();
System.out.println(“IV Base64 : ” + Base64.encode(iv));

byte[] encrypted = cipher.doFinal(plainText.getBytes());

return encrypted;
}

public static byte[] decrypt(byte[] encrypted, byte[] key, AlgorithmParameters ap)
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException,
InvalidParameterSpecException, InvalidAlgorithmParameterException {

if (encrypted == null || encrypted.length == 0 || key == null || key.length == 0) {

return new byte[0];
}

SecretKeySpec sks = new SecretKeySpec(key, ALGORITHM_NAME);

Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, sks, ap);

return cipher.doFinal(encrypted);
}

private static final String ALGORITHM_NAME = “AES”;
private static final String ALGORITHM = “AES/CBC/PKCS5Padding”;
}
————————————–[上記参照例]—————————————-

Eclipse juno Version Force.com error

Cannot complete the install because one or more required items could not be found.
Software being installed: Force.com IDE 25.0.0.201206181021 (com.salesforce.ide.feature.feature.group 25.0.0.201206181021)
Missing requirement: Force.com IDE 25.0.0.201206181021 (com.salesforce.ide.feature.feature.group 25.0.0.201206181021) requires ‘org.eclipse.update.ui 0.0.0’ but it could not be found

対応策:
———————————————-

It should be possible to fetch the deependency automatically through the marketplace but for me it’s not working…. so what would you need to do is install the org.eclipse.update.ui manually from e.g.
http://www.java2s.com/Code/Jar/o/Downloadorgeclipseupdateui32300v20100512jar.htm

上記URLからファイルダンロードして、eclipseのpluginsにコピーする

暗号化シンプル例

private static final String cryptoKey = ‘1234567890123456’;
public static String encryptedData(String s) {
Blob encryptedData = Crypto.encryptWithManagedIV(‘AES128’, Blob.valueOf(cryptoKey), Blob.valueOf(s));
return EncodingUtil.base64Encode(encryptedData);
}
public static String decryptedData(String s) {
Blob decryptedData = Crypto.decryptWithManagedIV(‘AES128’, Blob.valueOf(cryptoKey), EncodingUtil.base64Decode(s));
return decryptedData.toString();
}

メールの送受信の制限と回避

Winter ’12時点での制限

「メール to ケース」「ワークフロー系のメール」「それ以外のメール」で、それぞれ別にカウントされるのがポイントです。

対象 1日あたりの送受信件数
メール to ケース 2500通
・ワークフローの電子メールアラート
・承認プロセスの電子メールアラート
の合計
ユーザライセンス数(※1)×1000通
(但し、最大200万通まで)
上記以外のメール送受信の合計・活動からのメール送信
・メール一括送信(※2)
・登録情報照会
・オンデマンド メール to ケース
・Apexによるメール送受信
など
ユーザライセンス数(※1)×1000通
(但し、最大100万通まで)

※1 メール送信が可能なユーザライセンス数の合計
(Salesforceライセンス、Salesforce Platformライセンス、Chatter Onlyライセンスなどが含まれる)

※2 一度に送信可能な件数は、下記のようにエディションにより異なる
・Professional Edition:250通
・Enterprise Edition:500通
・Unlimited Edition:1000通

1000件以上送信したい場合、下記方法で、実装可能

1: WFのメールアラート機能を利用して、送信を行う

2:テンプレートを自由に切り替えしたい場合、

①メール送信キューオブジェクトを用意する

②上記送信キューオブジェクトに、メール送信本文を格納情報項目定義する、

WF:起動条件:送信キューデータ新規作成場合

WFのメールアラートの差込項目利用して、メール送信内容は、上記メール送信本文項目を差し込みする

③VF画面用意して、画面に、テンプレート一覧を表示して、選択したテンプレート内容にて、送信内容を更新をして

更新した内容は送信キューオブジェクトに新規作成する

WF起動して、メールアラートは最新本文項目を差し込みして、送信を行う