嘉義棒球場
享櫻 shine 和風西洋料理
花磚咖啡。淺嚐館
Total Pageviews
2018/09/30
2018/09/15
[Java] java.security.InvalidKeyException: Illegal key size or default parameters
Problem
When I try to use AES to do encryption and decryption, I got this error message:
How-To
JCE download link: http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html
Screenshot for Step 2
Screenshot for Step 3
Reference
[1] https://stackoverflow.com/questions/6481627/java-security-illegal-key-size-or-default-parameters
When I try to use AES to do encryption and decryption, I got this error message:
Exception in thread "main" java.security.InvalidKeyException: Illegal key size or default parameters at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1026) at javax.crypto.Cipher.implInit(Cipher.java:801) at javax.crypto.Cipher.chooseProvider(Cipher.java:864) at javax.crypto.Cipher.init(Cipher.java:1249) at javax.crypto.Cipher.init(Cipher.java:1186) at test.albert.security.AESUtils.encrypt(AESUtils.java:25) at test.albert.security.AESUtils.main(AESUtils.java:41)
How-To
JCE download link: http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html
Screenshot for Step 2
Screenshot for Step 3
Reference
[1] https://stackoverflow.com/questions/6481627/java-security-illegal-key-size-or-default-parameters
Labels:
Java
2018/09/14
[Neo4j] Using Spring Data to create / delete nodes and relationship
假設我想透過 Spring Data API 建立起以下的 graph:
架構規劃如下:
pom.xml 內容:
Value objects - Brand
Value objects - Product
Repository class - BrandRepository
Repository class - ProductRepository
Service class - BrandService
Service class - ProductService
Client class - App
application.properties (記錄連線資訊)
架構規劃如下:
pom.xml 內容:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>neo4j</groupId> <artifactId>springdata</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>springdata</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-neo4j</artifactId> <version>2.0.0.RELEASE</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.16.18</version> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>23.0</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <repositories> <repository> <id>spring-libs-release</id> <name>Spring Releases</name> <url>https://repo.spring.io/libs-release</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> </project>
Value objects - Brand
package neo4j.springdata.vo; import org.neo4j.ogm.annotation.GeneratedValue; import org.neo4j.ogm.annotation.Id; import org.neo4j.ogm.annotation.NodeEntity; import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.ToString; @NodeEntity @Data @ToString @NoArgsConstructor @RequiredArgsConstructor public class Brand { @Id @GeneratedValue private Long id; @NonNull private String name; }
Value objects - Product
package neo4j.springdata.vo; import org.neo4j.ogm.annotation.GeneratedValue; import org.neo4j.ogm.annotation.Id; import org.neo4j.ogm.annotation.NodeEntity; import org.neo4j.ogm.annotation.Relationship; import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.ToString; @NodeEntity @Data @ToString @NoArgsConstructor @RequiredArgsConstructor public class Product { @Id @GeneratedValue private Long id; @NonNull private String name; @Relationship(type = "MADE_BY") private Brand madeBy; }
Repository class - BrandRepository
package neo4j.springdata.repository; import org.springframework.data.neo4j.annotation.Query; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import neo4j.springdata.vo.Brand; @Repository public interface BrandRepository extends CrudRepository<Brand, Long>{ @Query("match(b:Brand) where b.name = {name} return b") Brand findByName(@Param("name") String name); @Query("match(n:Brand) optional match (n)-[r]-() delete r, n") void deleteAllBrands(); }
Repository class - ProductRepository
package neo4j.springdata.repository; import org.springframework.data.neo4j.annotation.Query; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import neo4j.springdata.vo.Product; @Repository public interface ProductRepository extends CrudRepository<Product, Long> { @Query("match (n:Product) optional match (n)-[r]-() delete r, n") void deleteAllProducts(); }
Service class - BrandService
package neo4j.springdata.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import neo4j.springdata.repository.BrandRepository; import neo4j.springdata.vo.Brand; @Service public class BrandService { @Autowired private BrandRepository brandRepo; public void createBrands(List<Brand> brands) { brandRepo.saveAll(brands); } public void deleteAllBrands() { brandRepo.deleteAllBrands(); } }
Service class - ProductService
package neo4j.springdata.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import neo4j.springdata.repository.BrandRepository; import neo4j.springdata.repository.ProductRepository; import neo4j.springdata.vo.Brand; import neo4j.springdata.vo.Product; @Service public class ProductService { @Autowired private BrandRepository brandRepo; @Autowired private ProductRepository productRepo; public void createProducts(List<Product> products, String brandName) { Brand brand = brandRepo.findByName(brandName); products.forEach(p -> p.setMadeBy(brand)); productRepo.saveAll(products); } public void deleteAllProducts() { productRepo.deleteAllProducts(); } }
Client class - App
package neo4j.springdata; import java.util.List; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories; import com.google.common.collect.Lists; import neo4j.springdata.service.BrandService; import neo4j.springdata.service.ProductService; import neo4j.springdata.vo.Brand; import neo4j.springdata.vo.Product; @SpringBootApplication @EnableNeo4jRepositories public class App { public static void main(String[] args) { SpringApplication.run(App.class, args); } @Bean CommandLineRunner createBrands(BrandService brandService) { return args -> { List<Brand> brands = Lists.newArrayList(new Brand("Apple"), new Brand("Google"), new Brand("Samsung")); brandService.createBrands(brands); }; } @Bean CommandLineRunner createProducts(ProductService productService) { return args -> { List<Product> appleProducts = Lists.newArrayList(new Product("iPhne"), new Product("iPad"), new Product("iPad Pro"), new Product("MacBook"), new Product("MackBook Pro")); productService.createProducts(appleProducts, "Apple"); List<Product> googleProducts = Lists.newArrayList(new Product("Nexus 6P"), new Product("Nexus 5X"), new Product("Chromecast")); productService.createProducts(googleProducts, "Google"); List<Product> samsungProducts = Lists.newArrayList(new Product("Samsung Galaxy Note 8"), new Product("Samsung Galaxy Note FE"), new Product("Samsung Galaxy S9"), new Product("Samsung Galaxy A8")); productService.createProducts(samsungProducts, "Samsung"); }; } @Bean CommandLineRunner deleteProductAndBrands(BrandService brandService, ProductService productService) { return args -> { brandService.deleteAllBrands(); productService.deleteAllProducts(); }; } }
application.properties (記錄連線資訊)
spring.data.neo4j.uri=bolt://localhost spring.data.neo4j.username=neo4j spring.data.neo4j.password=secret
2018/09/13
[Neo4j] Forgot password to log into Neo4j server
Problem
If I forgot my password to log into Neo4j server, how to reset it?
How-To
Screenshot for Step1 (Find auth file in your neo4j directory)
Screenshot for Step3 (Restart neo4j server)
Screenshot for Step4 (Open neo4j browser and login using default credentials, neo4j/neo4j )
Screenshot for Step5 (Enter new password)
If I forgot my password to log into Neo4j server, how to reset it?
How-To
Screenshot for Step1 (Find auth file in your neo4j directory)
Screenshot for Step3 (Restart neo4j server)
Screenshot for Step4 (Open neo4j browser and login using default credentials, neo4j/neo4j )
Screenshot for Step5 (Enter new password)
Labels:
Neo4j
2018/09/12
[Neo4j] How to find nodes and its relationships from existing graph
目前的 graph 如下
假設我要找出大雄與其他人之間的關係,Cypher 語法如下:
於 Neo4j Browser 執行結果:
假設我要找出大雄與其他人之間的關係,Cypher 語法如下:
match (m) where m.name="大雄" match (m)-[r]-(n) with m, n, type(r) as relationships return m.name, n.name, relationships
於 Neo4j Browser 執行結果:
Labels:
Neo4j
2018/09/11
[Neo4j] How to delete relationship/node from existing graph
目前的關係圖如下:
假設我要刪除大雄與小衫之間的情敵關係,Cypher 語法如下:
於 Neo4j Browser 執行結果:
更新後的 graph (大雄與小衫之間的情敵關係已刪除):
若我想要刪除小衫 (要先刪除小衫與他人的關係以後,才能刪除小衫),Cypher 語法如下:
於 Neo4j Browser 執行結果:
更新後的 graph (小衫已刪除):
假設我要刪除大雄與小衫之間的情敵關係,Cypher 語法如下:
// 找出大雄與小杉的 nodes match (m) where m.name="大雄" match (n) where n.name="小杉" // 找出兩人間糾葛的情敵關係 match (n)-[r:RIVAL_OF]->(m) // 刪除情敵關係 delete r
於 Neo4j Browser 執行結果:
更新後的 graph (大雄與小衫之間的情敵關係已刪除):
若我想要刪除小衫 (要先刪除小衫與他人的關係以後,才能刪除小衫),Cypher 語法如下:
// 找出小杉的 nodes match (n) where n.name="小杉" // 找出小衫與他人的關係 OPTIONAL MATCH (n)-[r]-() // 刪除小衫以及小衫與他人的關係 delete r, n
於 Neo4j Browser 執行結果:
更新後的 graph (小衫已刪除):
Labels:
Neo4j
2018/09/10
[Neo4j] How to create nodes / relationships to existing graph
目前的關係圖如下:
若我想要:
1. 建立一位新人物,叫做小衫
2. 建立一個新關係,靜香與小衫是朋友關係
3. 再建立一個新關係,大雄與小衫是情敵關係
Cypher 語法如下:
於 Neo4j Browser 執行結果:
若我想要找出最新的 graph
Cypher 語法如下:
於 Neo4j Browser 執行結果:
若我想要:
1. 建立一位新人物,叫做小衫
2. 建立一個新關係,靜香與小衫是朋友關係
3. 再建立一個新關係,大雄與小衫是情敵關係
Cypher 語法如下:
// 建立小衫 create(p:Person {id:"9", name:"小杉", gender:"男性"}) with p // 找出靜香與大雄的 nodes match (n) where n.name="靜香" match (m) where m.name="大雄" // 建立新關係:靜香與小衫是朋友關係 create (p)-[:FRIEND_OF]->(n) // 建立新關係:大雄與小衫是情敵關係 create (p)-[:RIVAL_OF]->(m)
於 Neo4j Browser 執行結果:
若我想要找出最新的 graph
Cypher 語法如下:
// 找出所有關聯圖 match (all) return all
於 Neo4j Browser 執行結果:
Labels:
Neo4j
Subscribe to:
Posts (Atom)